问题
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