简体   繁体   English

如何在tomcat 6.0集群环境中实现缓存同步?

[英]How to implement cache synchronization in tomcat 6.0 cluster environment?

I'm currently working on a migration a web application to run in a cluster. 我目前正致力于迁移Web应用程序以在群集中运行。 This application uses caches. 此应用程序使用缓存。 Some of this caches are reloaded in case the user saves something. 如果用户保存了某些内容,则会重新加载某些缓存。 I'ld like to inform the other nodes of the cluster about this, so that all nodes refresh their caches. 我想通知集群的其他节点,以便所有节点刷新它们的缓存。

It seems that the tomcat server has a group messaging build in. (Tribes) I'm wondering if I can use this messaging for my task and how to have the event listener run the whole day then. 似乎tomcat服务器有一个组消息传递内置。(Tribes)我想知道我是否可以将这个消息传递用于我的任务以及如何让事件监听器运行一整天。

with kind regards Michael 亲切的问候迈克尔

If you are using handwritten CACHE, Than you can synchronize cache B/W all nodes of cluster using message broadcasting/receiving , You can use JGROUP for that. 如果您使用手写CACHE,您可以使用消息广播/接收来同步缓存B / W群集的所有节点,您可以使用JGROUP

for ex: node A update cache that it just broad cast message to other node to refill( refresh ) their cache for ex:node一个更新缓存,它只是广泛地将消息转发给其他节点以重新填充( refresh )它们的缓存

It is possible to use it and there is no need to start a thread or the like. 可以使用它并且不需要启动线程等。 Sending class instances around requires a jar of the message class in tomcat lib directory. 发送类实例需要tomcat lib目录中的jar消息类。

cheers Michae 欢呼Michae

You can use Hazelcast Topic. 您可以使用Hazelcast主题。 It is a very lightweight pub/sub messaging. 它是一个非常轻量级的发布/订阅消息。 Each node will listen to the topic. 每个节点都会收听该主题。 When user saves smth on any node just put some message "REFRESH". 当用户在任何节点上保存smth时,只需输入一些消息“REFRESH”。 On receive each node can do whatever you want. 在接收时,每个节点都可以执行任何操作。 Here is the code to do this: 这是执行此操作的代码:

String REFRESH = "REFRESH";
ITopic<String> topic = Hazelcast.getTopic("myTopic");
topic.addMessageListener(new MessageListener<String>() {
        public void onMessage(String msg) {
          if(REFRESH.equals(msg){   
           //do refresh
          }
        }
    });

//when user saves sth. //当用户保存某事时
topic.publish(REFRESH); topic.publish(刷新);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM