一台电脑两个tomcat 模仿集群session共享,ehcache 里面的内容无法同步进入
第一个XML
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<diskStore path="D:\cache" />
<defaultCache maxElementsInMemory="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120" diskSpoolBufferSizeMB="30"
maxElementsOnDisk="10000000" diskExpiryThreadIntervalSeconds="120">
</defaultCache>
<cache name="test1" maxElementsInMemory="100" maxElementsOnDisk="0"
eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="0">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=true,replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true "/>
</cache>
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,
rmiUrls=//localhost:8090/test1" />
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=localhost, port=8091,
socketTimeoutMillis=2000"/>
</ehcache>
第二个:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<diskStore path="D:\cache" />
<defaultCache maxElementsInMemory="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120" diskSpoolBufferSizeMB="30"
maxElementsOnDisk="10000000" diskExpiryThreadIntervalSeconds="120">
</defaultCache>
<cache name="test1" maxElementsInMemory="100" maxElementsOnDisk="0"
eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="0">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=true,replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true "/>
</cache>
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=manual,
rmiUrls=//localhost:8091/test1" />
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=localhost, port=8090,
socketTimeoutMillis=2000"/>
</ehcache>
测试的额
CacheManager manager = new CacheManager("E:\\workspace\\jeesite-yjy\\src\\main\\resources\\cache\\ehcache-rmi.xml");
//get Cache
Cache cache = manager.getCache("test1");
Thread.sleep(10000);
Element element = new Element("key","test");
cache.put(element);
System.out.println("Initial:\n"//+url.toString()
+"\n"+manager.getName()
+"\n"+cache.getName()
+" 's size = "+cache.getSize()
+"\n"+element.toString());
CacheManager manager = new CacheManager("E:\\workspace\\jeesite-yjy2\\src\\main\\resources\\cache\\ehcache-rmi.xml");
//get Cache
Cache cache = manager.getCache("test1");
Thread.sleep(1000);
while(true){
System.out.println("搜索中...");
System.out.println("当前资源数:" + cache.getSize());
Element element = cache.get("key");
if (element != null) {
System.out.println(element.getValue());
break;
}
Thread.sleep(1000);
}
跪求大神