ehcache jgroup缓存同步

这几天研究ehcache jgroup同步缓存,照着官方例子做了做,一直出错,,原来官方例子有点错误

 

http://www.ehcache.org/generated/2.9.0/html/ehc-all/#page/Ehcache_Documentation_Set%2Fco-jgrp_common_issues_with_jgroup_replication.html%23
 

 

首先,包依赖如下:

<dependency>
			<groupId>net.sf.ehcache</groupId>
			<artifactId>ehcache</artifactId>
			<version>2.9.1</version>
		</dependency>
		<dependency>
			<groupId>org.jgroups</groupId>
			<artifactId>jgroups</artifactId>
			<version>3.6.3.Final</version>
		</dependency>
		<dependency>
			<groupId>net.sf.ehcache</groupId>
			<artifactId>ehcache-jgroupsreplication</artifactId>
			<version>1.7</version>
		</dependency>

 

ehcache配置:

 

<defaultCache maxElementsInMemory="10000" eternal="false"
		overflowToDisk="true" timeToIdleSeconds="500" timeToLiveSeconds="1000"
		diskPersistent="false" diskExpiryThreadIntervalSeconds="120">
		<cacheEventListenerFactory
			class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
			properties="replicateAsynchronously=true, replicatePuts=true,  
                            replicatePutsViaCopy=true, replicateUpdates=true,  
                            replicateUpdatesViaCopy=true, replicateRemovals=true" />
		<bootstrapCacheLoaderFactory
			class="net.sf.ehcache.distribution.jgroups.JGroupsBootstrapCacheLoaderFactory"
			properties="bootstrapAsynchronously=false" />
	</defaultCache>


<!-- TCP -->
	<cacheManagerPeerProviderFactory
		class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
		properties="channel=ehcache:connect=TCP(bind_port=8080):TCPPING(initial_hosts=192.168.1.238[8080];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=":" />

或者UDP方式,二选一

<!-- UDP -->
	<cacheManagerPeerProviderFactory
		class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
		properties="channel=ehcache:connect=UDP(mcast_addr=192.168.1.238;mcast_port=8080;):PING:MERGE2:FD_SOCK:VERIFY_SUSPECT:pbcast.NAKACK:UNICAST:pbcast.STABLE:FRAG:pbcast.GMS"
		propertySeparator=":" />
 要注意,TCP为bind_port,而不是start_port,propertySeparator配置,官方示例写错了,多写了个分号(:)

 

 如果是 Tomcat 服务器,可在 catalina.bat 或者 catalina.sh 中增加如下环境变量即可:
SET CATALINA_OPTS=-Djava.net.preferIPv4Stack=true

你可能感兴趣的:(ehcache)