Ralph
Ralph

Reputation: 120811

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

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:

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

Upvotes: 9

Views: 5013

Answers (2)

Tasos P.
Tasos P.

Reputation: 4114

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)

Upvotes: 10

Preston
Preston

Reputation: 3271

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.

Upvotes: 0

Related Questions