In a Tomcat cluster, how to share beans in an application?

左心房为你撑大大i 提交于 2019-12-11 12:27:29

问题


This might sound like a dumb or a simple question, but I really have little to no experience with clustering of any kind and I'm just curious if and how a certain scenario is possible.

Let's say I've set up a cluster of N Tomcat instances, and I've deployed my application App1 across all N instances.

What would I need to do to be able to have certain beans in the application - not all, but some - be "shared" across the cluster?

i.e., if I had a bean for WebsiteSettings, I'd like to have some lookup process where the application could ask for the bean and be given an instance of it, and any updates to the bean's properties/values are also available to any other machines in the cluster, i.e., WebsiteSettings.getGreeting() would return the same value on all N machines whenever it was updated.

Do I need to set these beans up as MBeans, and have App1 look them up via JMX? Will Tomcat's clustering support then take care of replicating changes in the MBean to all node's in the cluster automatically?


回答1:


Please take a look at Terracotta - it allows you to have the same object (in a way) reside on many instances, where all the updates of the other nodes are done seamlessle in the JVM level and not in your code.

You may want to take a look at this for further information - What Is Terracotta




回答2:


One option is to use a shared distributed cache. There are several available which would easily give you this functionality.



来源:https://stackoverflow.com/questions/848568/in-a-tomcat-cluster-how-to-share-beans-in-an-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!