Ehcache利用RMI方式同步缓存

Ehcache缓存同步有几种方式:(1)RMI (2)Terrocotta (3)JMS (4)JGroups

先介绍下,利用RMI进行缓存同步。

 

测试类1:在sampleDistributedCache2缓存中查找是否存在ehcache键,如果没找到,则打印NotFound;如果找到了,则打印相应值

 

配置文件1:将官方样例文件中相应位置替换即可

(1)其他JVM提供缓存的rmiUrl地址

(2)监听来自于其他复制节点消息的本JVM的host,port

(3)配置复制选项,启动时同步等

 

 

测试类2:向sampleDistributedCache2缓存中添加ehcache键

 

配置文件:将官方样例文件中相应位置替换即可

 

运行结果:

JVM1

2009-12-13 12:24:04 net.sf.ehcache.distribution.RMICacheManagerPeerListener <init>
警告: Explicitly setting the listener hostname to 'localhost' is not recommended. It will only work if all CacheManager peers are on the same machine.
=======================
sampleDistributedCache2
sampleCache2
sampleCache1
sample/DistributedCache3
sampleDistributedCache1
sampleCache3
=======================
sampleDistributedCache2
sampleCache2
sampleCache1
sample/DistributedCache3
sampleCache3
=======================
sampleDistributedCache2
sampleCache2
Test1
sampleCache1
sample/DistributedCache3
sampleCache3
key0=value0 has been added
key1=value1 has been added
key2=value2 has been added
key3=value3 has been added
key4=value4 has been added
key5=value5 has been added
key6=value6 has been added
key7=value7 has been added
key8=value8 has been added
key9=value9 has been added
key7=value7 has been evicted
key10=value10 has been added
key0=value0 has been evicted
key11=value11 has been added
key9=value9 has been evicted
key12=value12 has been added
key3=value3 has been evicted
key13=value13 has been added
key1=value1 has been evicted
key14=value14 has been added
key4=value4 has been evicted
key15=value15 has been added
key13=value13 has been evicted
key16=value16 has been added
key8=value8 has been evicted
key17=value17 has been added
key17=value17 has been evicted
key18=value18 has been added
key18=value18 has been evicted
key19=value19 has been added
NotFound
newaddvalue

JVM2:

2009-12-13 12:24:13 net.sf.ehcache.distribution.RMICacheManagerPeerListener <init>
警告: Explicitly setting the listener hostname to 'localhost' is not recommended. It will only work if all CacheManager peers are on the same machine.
=======================
sampleDistributedCache2
sampleCache2
sampleCache1
sample/DistributedCache3
sampleDistributedCache1
sampleCache3
size=10;memsize=10;diskSize=0;hits=0;missed=0;liveHits=0;liveMissed=0;hitsOnDisk=0

阅读更多
个人分类: Java相关
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

Ehcache利用RMI方式同步缓存

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭