如何在WAS集群中的两台不同服务器上触发代码?
我在 Web 应用程序中有一个管理页面可以重置缓存,但它只重置当前 JVM 上的缓存。
Web 应用程序作为集群部署到两台 WAS 服务器。
有什么方法可以优雅地让每台服务器上的“清除缓存”按钮触发两个 JVM 上的方法吗?
编辑: 最初的开发人员只是编写了一个包含 HashMap 的单例作为有问题的缓存。轻量级并且(以前)可以很好地满足要求。它将从六个或七个 Web 服务中提取的内容缓存指定的时间。
编辑: 整个应用程序有三页,因此优雅的解决方案很可能是最轻量的解决方案。
I have an administrative page in a web application that resets the cache, but it only resets the cache on the current JVM.
The web application is deployed as a cluster to two WAS servers.
Any way that I can elegantly have the "clear cache" button on each server trigger the method on both JVMs?
Edit:
The original developer just wrote a singleton holding a HashMap to be the cache in question. Lightweight and (previously) worked just fine for the requirements. It caches content pulled from six or seven web services for specified amounts of time.
Edit:
The entire application in question is three pages, so the elegant solution might well be the lightest solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于缓存位于应用程序内部,因此您需要提供一个接口来在应用程序中清除缓存。 Quotidian 说使用 JMS 队列。这是行不通的,因为假设您有集群 MQ 队列,则只有一个实例会接收消息。
如果您想重用相同的实现,那么唯一的方法是编写一些您能够在实例级别进行交互的 JMX。
如果没有,您可以使用内置的 WAS 缓存(启用了 JMX)或使用像 ehcache 这样的分布式缓存。
过去,我创建了一个子类 LinkedHashMap,它使用 JBOSS JGroups 链接到网络上的所有实例。当然,重新发明轮子总是痛苦的。
Since the Cache is internal to your application you are going to need to provide an interface to clear it within your application. Quotidian says to use a JMS queue. That will not work because only one instance will pick up the message assuming you have clustered MQ Queues.
If you want to reuse the same implementation then the only way to do this is to write some JMX that you will be able to interact with at the instance level.
If not you can either use the built in WAS cache (which is JMX enabled) or use a distributed cache like ehcache.
in the past I have created a subclassed LinkedHashMap that was linked to all instances on the network using JBOSS JGroups. Of course reinventing the wheel is always painful.
我倾向于使用 JMS 队列来做到这一点。
I tend to use a JMS queue for doing exactly that.