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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值