How to run a Scheduled Method in a Cluster for one Node and for All?

我们两清 提交于 2019-12-20 20:38:45

问题


I have a Glassfish 3.1.2 that runs in a cluster and a EJB 3.1 application. And I need two kind of Scheduled Methods in my application:

  • one kind that runs only once (on a single node) once a day
  • and other kind that runs on all nodes (every 1-2 Minutes) -- They do NOT need to run a syncron way! The requirement is just that this kind run on every node.

I have no clue how to start with this cluster - problem, is this possible with @Schedule (and how) or do I need something else?


回答1:


I faced the exact same issue (need one cluster timer and a per node timer) and came across this question. So, for anyone interested:

If you declare the timer with @Schedule(..., persistent=true), you will get a cluster timer stored in the timer db (which can be migrated)

If you declare the timer with @Schedule(..., persistent=false), you will get a node timer not stored in the timer db (which can't be migrated)




回答2:


You could look at using JMS. For the method that needs to run on a single node, use a queue and for the ones that need to run on all nodes use a topic.



来源:https://stackoverflow.com/questions/11244608/how-to-run-a-scheduled-method-in-a-cluster-for-one-node-and-for-all

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