Hi Leonardo,

Never feel like a question is dumb if you're searching for an answer. That's why we are here.

You will find information on clustering Quartz using a JDBC JobStore here: http://quartz-scheduler.org/generated/2.2.1/html/qs-all/#page/Quartz_Scheduler_Documentation_Set/re-cls_cluster_configuration.html#

Just make sure those properties are consistent across your TomEE cluster and you'll be fine.

The @Schedule is more tricky as you will be responsible for obtaining a cluster wide lock from that method. The easiest way would be to configure a DataSource to a central database that is accessible by all the TomEE instances in the cluster - Use a simple table with a BIT type and a DATETIME Whichever '@Schedule' method gets the lock can then run the operation (and unlock afterwards, so use a try/finally block) - The date can be used to check for a lock timeout if a method fails to unlock for whatever reason (a crash for example).

Andy.

On 16/10/2014 12:27, Leonardo K. Shikida wrote:
Hi

this doubt may sound dumb, but if I have an EJB with a scheduled task like

     @Schedule(dayOfWeek = "*")
     public void runMeDaily() {...}

and if I am in a clustered environment, is there any way to make this job
run in only one of the instances? (only once)

of course, I can set a flag somewhere and check it before the execution of
such task, so only the first cluster instance would run it, but I am
curious if it's possible using some configuration magic.

another doubt is: if I have 2 clustered tomee instances, how do I make both
point to the same scheduler? By scheduler I mean something like

Scheduler scheduler = new StdSchedulerFactory().getScheduler("myScheduler");

My feeling is that my cluster will need a centralized quartz scheduler
service somehow, so if there's some way to do that using tomee, it would be
useful for me.

TIA

Leo



--
  Andy Gumbrecht
  https://twitter.com/AndyGeeDe
  http://www.tomitribe.com

Reply via email to