ehcache缓存集群
来源:互联网 发布:网络发稿价格 编辑:程序博客网 时间:2024/06/10 15:00
Ehcache支持的分布式缓存支持有三种RMI,JGroups,JMS,这里介绍下MRI和JGrpups两种方式,Ehcache使用版本为1.5.0,关于ehcache的其他信息请参考http://ehcache.sourceforge.net/EhcacheUserGuide.html,关于jgroups的信息请参考http://www.jgroups.org/manual/html_single/index.html。
环境为两台机器 server1 ip:192.168.2.154,server2 ip:192.168.2.23
1. RMI方式:
rmi的方式配置要点(下面均是server1上的配置,server2上的只需要把ip兑换即可)
a. 配置PeerProvider:
- <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
- properties="peerDiscovery=manual,rmiUrls=//192.168.2.23:40001/userCache|//192.168.2.23:40001/resourceCache" />
配置中通过手动方式同步sever2中的userCache和resourceCache。
b. 配置CacheManagerPeerListener:
- <cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
- properties="hostName=192.168.2.154, port=40001,socketTimeoutMillis=2000" />
配置中server1监听本机40001端口。
c. 在每一个cache中添加cacheEventListener,例子如下:
- <cache name="userCache" maxElementsInMemory="10000" eternal="true" overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0" diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
- <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true,replicateUpdatesViaCopy= false, replicateRemovals= true " />
- </cache>
2. JGroups方式:
ehcache 1.5.0之后版本支持的一种方式,配置起来比较简单,要点:
a. 配置PeerProvider,使用tcp的方式,例子如下:
- <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
- properties="connect=TCP(start_port=7800):
- TCPPING(initial_hosts=192.168.2.154[7800],192.168.2.23[7800];port_range=10;timeout=3000;
- num_initial_members=3;up_thread=true;down_thread=true):
- VERIFY_SUSPECT(timeout=1500;down_thread=false;up_thread=false):
- pbcast.NAKACK(down_thread=true;up_thread=true;gc_lag=100;retransmit_timeout=3000):
- pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;
- print_local_addr=false;down_thread=true;up_thread=true)"
- propertySeparator="::" />
b.为每个cache添加cacheEventListener:
- <cache name="userCache" maxElementsInMemory="10000" eternal="true"
- overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0"
- diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
- <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
- properties="replicateAsynchronously=true, replicatePuts=true,
- replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true"/>
- </cache>
JGroup方式配置的两个server上的配置文件一样,若有多个server,在initial_hosts中将server ip加上即可。
一个完整的ehcache.xml文件:
- <?xml version="1.0" encoding="UTF-8"?>
- <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:noNamespaceSchemaLocation="http://ehcache.sf.net/ehcache.xsd">
- <diskStore path="java.io.tmpdir" />
- <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
- properties="connect=TCP(start_port=7800):
- TCPPING(initial_hosts=192.168.2.154[7800],192.168.2.23[7800];port_range=10;timeout=3000;
- num_initial_members=3;up_thread=true;down_thread=true):
- VERIFY_SUSPECT(timeout=1500;down_thread=false;up_thread=false):
- pbcast.NAKACK(down_thread=true;up_thread=true;gc_lag=100;retransmit_timeout=3000):
- pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;
- print_local_addr=false;down_thread=true;up_thread=true)"
- propertySeparator="::" />
- <defaultCache maxElementsInMemory="10000" eternal="true"
- overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0"
- diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
- <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
- properties="replicateAsynchronously=true, replicatePuts=true,
- replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true"/>
- </defaultCache>
- <cache name="velcroCache" maxElementsInMemory="10000" eternal="true"
- overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0"
- diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
- <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
- properties="replicateAsynchronously=true, replicatePuts=true,
- replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true"/>
- </cache>
- <cache name="userCache" maxElementsInMemory="10000" eternal="true"
- overflowToDisk="true" timeToIdleSeconds="0" timeToLiveSeconds="0"
- diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
- <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
- properties="replicateAsynchronously=true, replicatePuts=true,
- replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true"/>
- </cache>
- <cache name="resourceCache" maxElementsInMemory="10000"
- eternal="true" overflowToDisk="true" timeToIdleSeconds="0"
- timeToLiveSeconds="0" diskPersistent="false"
- diskExpiryThreadIntervalSeconds="120">
- <cacheEventListenerFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
- properties="replicateAsynchronously=true, replicatePuts=true,
- replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true"/>
- </cache>
- </ehcache>
- ehcache缓存集群
- ehcache集群缓存配置
- ehcache集群缓存配置
- EhCache 分布式缓存/缓存集群
- EhCache 分布式缓存/缓存集群
- EhCache 分布式缓存/缓存集群
- EhCache 分布式缓存/缓存集群
- EhCache 分布式缓存/缓存集群
- EhCache 分布式缓存/缓存集群
- EhCache 分布式缓存/缓存集群
- EhCache 分布式缓存/缓存集群
- EhCache 分布式缓存/缓存集群
- EhCache 分布式缓存/缓存集群
- EhCache 分布式缓存/缓存集群
- EhCache 分布式缓存/缓存集群
- EhCache 分布式缓存/缓存集群
- EhCache 分布式缓存/缓存集群
- EhCache 分布式缓存/缓存集群
- 多表建立视图,用于站内搜索!
- java 面试题59道(含参考答案)
- Java程序员转到C++开发容易发生的疏漏。
- 新的起点
- 如何进行文献检索和阅读(转)
- ehcache缓存集群
- 删除图片链接的蓝色边框和点击后的虚线框!
- JAVA笔试题精华版1.0
- 新的起点
- 什么是模式?什么是框架?软件为什么要分层?【转】
- 页面中禁止Enter键!
- 4.2--如何使 对话框 在 另一个窗口 里居中?
- java程序员面试必备的32个要点
- 后台调试js,整体刷新frame框架!