ehcache改造,应用间共享RMI

1、配置

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" monitoring="autodetect" dynamicConfig="true">  
    <diskStore path="java.io.tempdir" />  
    <defaultCache maxElementsInMemory="1000" eternal="false"  
        timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" />
        
    <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" 
        properties="peerDiscovery=manual,rmiUrls=//localhost:40001/ehcache-app" propertySeparator=","/>
        
    <cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
        properties="hostName=localhost, port=40002, socketTimeoutMillis=2000"/>
        
   <cache name="ehcache-app" maxElementsInMemory="10000"  
        eternal="true" 
        overflowToDisk="true">  
        <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
            properties="replicateAsynchronously=true,replicatePuts=true,replicatePutsViaCopy=true,
            replicateUpdates=true,replicateUpdatesViaCopy=true, replicateRemovals=true,
            asynchronousReplicationIntervalMillis=200"/>
        <bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"/>
    </cache>  
</ehcache>  

 

这里主要设置缓存名称name="ehcache-app",cacheManagerPeerListenerFactory,cacheManagerPeerProviderFactory,根据不同应用设置不同值。个人只测试了2个应用间共享,hostName设置成服务器ip地址,注意防火墙打开时,设置的端口开放。

A应用:

<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" 
        properties="peerDiscovery=manual,rmiUrls=//localhost:40001/ehcache-app" propertySeparator=","/>
        
    <cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
        properties="hostName=localhost, port=40002, socketTimeoutMillis=2000"/>

 

B应用:

<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" 
        properties="peerDiscovery=manual,rmiUrls=//localhost:40002/ehcache-app" propertySeparator=","/>
        
    <cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
        properties="hostName=localhost, port=40002, socketTimeoutMillis=2000"/>

 

2、程序读取配置

在本地配置基础上增加:

         MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
         ManagementService.registerMBeans(cacheManager, mBeanServer, true, true,
         true, true);

 

将CacheManager cacheManager注册到ManagementService即可,其他不变。

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值