一个ehcache RMI集群里面有三个节点【A,B ,C】,他们依次启动,B节点不能同步A B连个节点所有数据,两端节点A,C可以同步其它两个节点所有信息。为什么?
A节点测试代码
// PropertyConfigurator.configure("src/main/config/log4j.properties");
CacheManager manager = new CacheManager("src/test/config/ehcache_cluster1.xml");
// 取得Cache
Cache cache = manager.getCache("UserCache");
Element element = new Element("client1" + System.currentTimeMillis(), "client1");
cache.put(element);
while (true)
{
Thread.sleep(5000);
System.out.println("\n");
for (Object key : cache.getKeys())
{
System.out.println(key + ":" + cache.get(key));
}
B节点测试代码
CacheManager manager = new CacheManager("src/test/config/ehcache_cluster2.xml");
Cache cache = manager.getCache("UserCache");
Element element = new Element("client2" + System.currentTimeMillis(), "client2");
cache.put(element);
while (true)
{
Thread.sleep(5000);
System.out.println("\n");
for (Object key : cache.getKeys())
{
System.out.println(key + ":" + cache.get(key));
}
}
C节点测试代码
CacheManager manager = new CacheManager("src/test/config/ehcache_cluster3.xml");
Cache cache = manager.getCache("UserCache");
Element element = new Element("client3" + System.currentTimeMillis(), "client3");
cache.put(element);
while (true)
{
Thread.sleep(5000);
System.out.println("\n");
for (Object key : cache.getKeys())
{
System.out.println(key + ":" + cache.get(key));
}
}
ehcache_cluster1.xml
<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|rmiUrls=//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=false, replicatePuts=true,
replicatePutsViaCopy=true, replicateUpdates=true,
replicateUpdatesViaCopy=true, replicateRemovals=true,
asynchronousReplicationIntervalMillis=200" />
<bootstrapCacheLoaderFactory
class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />
</cache>
</ehcache>
ehcache_cluster2.xml
<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:40001/UserCache|rmiUrls=//localhost:40003/UserCache" />
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=localhost,port=40002, socketTimeoutMillis=2000" />
<cache name="UserCache" maxElementsInMemory="10000">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=false, replicatePuts=true,
replicatePutsViaCopy=true, replicateUpdates=true,
replicateUpdatesViaCopy=true, replicateRemovals=true,
asynchronousReplicationIntervalMillis=200" />
<bootstrapCacheLoaderFactory
class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />
</cache>
</ehcache>
ehcache_cluster3.xml
<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=//10.114.195.218:40001/UserCache|rmiUrls=//10.114.195.218:40002/UserCache" />
<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=10.114.195.218,port=40003, socketTimeoutMillis=2000" />
<cache name="UserCache" maxElementsInMemory="10000">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=false, replicatePuts=true,
replicatePutsViaCopy=true, replicateUpdates=true,
replicateUpdatesViaCopy=true, replicateRemovals=true,
asynchronousReplicationIntervalMillis=200" />
<bootstrapCacheLoaderFactory class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />
</cache>
</ehcache>
相关推荐
NULL 博文链接:https://caerun.iteye.com/blog/1853860
ehcahce通过RMI方式进行集群的demo,myeclipse导入后直接可以运行。
ehcache集群同步配置实例加说明文档
ehcache集群方案
Ehcache集群实例 Ehcache jgroups Ehcache rmi
RMI+EHCACHE可以做基础学习理解
异步复制与同步复制 以及ehcache的小tips和我的配置
ehcache jgroups方式集群,根据网上的资料自己摸索修改的,欢迎下载
当有数据更新的时候,每个进程中的缓存都是独立维护的,如果这些进程缓存同步机制,那么就存在因缓存没有更新,而一直都用已经失效的缓存返回给用户,这样的逻辑显然是会有问题的。所以,本文就来说说当使用EhCache...
ehcache3集群相关资源,包括ehcache-clustered-3.10.0-kit、ehcache-3.10.0.jar、ehcache-clustered-3.10.0.jar、terracotta-3.7.7.tar.gz、ehcache-transactions-3.10.0.jar
Ehcache通过使用Jgroups做集群配置,更改每一个不同的jgroups.xml文件的端口号和IP,如果一台机器就使用127.0.0.1即可。配置好之后,把每台机器起来,就可以测试了。
EHCAHCE基于JGROUP的集群配置方案,内含相关配置文件,及配置说明
ehcache提供三种网络连接策略来实现集群,rmi,jgroup还有jms。这里只说rmi方式。同时ehcache可以可以实现多播的方式实现集群。也可以手动指定集群主机序列实现集群,本例应用手动指定。
NULL 博文链接:https://nassir.iteye.com/blog/1602372
Ehcache集群环境配置
此为ehcache的使用以及集群的使用,具体需要两台机子,将ehcache 的hostName替换相应的ip即可
EhCache 是一个纯 Java 的进程内缓存框架,具有快速、精干等特点,是 Hibernate 中默认的 CacheProvider。Ehcache 是一种广泛使用的开源 Java 分布式缓存。主要面向通用缓存,Java EE 和轻量级容器。它具有内存和...
具有集群支持的 Ehcache 3(ehcache-clustered-3.8.1-kit.zip)
Ehcache集群配置手册帮助你梳理Ehcache集群部署的配置
使用ehcache rmi 手动发现(manual)进行集群同步的示例.