Ehcache RMI Replicated Cluster(RMI集群)

[quote]本文是ehcache RMI集群的例子,导入附件中的java 项目到eclipse中,依次启动附件中的A.java,B.java,C.java, 就可以在eclipse的console中就可以看到3个cache的内容同步啦[/quote]

1. ehcache 配置文件
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd">
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,
rmiUrls=//localhost:40002/UserCache|//localhost:40003/UserCache" />

<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=localhost,port=40001, socketTimeoutMillis=2000" />

<cache name="UserCache" maxElementsInMemory="10000" >
<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>



2. A.java
	
CacheManager manager = new CacheManager("config/ehcache_cluster1.xml");

// 取得Cache
Cache cache = manager.getCache("UserCache");
Element element = new Element("Client A", "A");
cache.put(element);
while (true)
{
Thread.sleep(5000);
System.out.println("\n");
for (Object key : cache.getKeys())
{
System.out.println(key + ":" + cache.get(key));
}
cache.put(new Element("client A" + System.currentTimeMillis(), "client1"));
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值