views:

106

answers:

2

Hi, I have multiple quartz cron jobs in a load balanced environment. Currently these jobs are running on each node, which is not desirable. I want a node to run only a particular scheduler and if the node crashes, another node should run the scheduler intended for the node that crashed. How can this be done with spring 2.5.6/tomcat load balancer.

A: 

I think there's a few aspects to this question.

Firstly, Quartz has API methods for pausing and resuming the Scheduler, or even individual triggers and jobs

e.g. http://www.jarvana.com/jarvana/view/opensymphony/quartz/1.6.1/quartz-1.6.1-javadoc.jar!/org/quartz/Scheduler.html#standby()

I would create a spring bean with a reference to the Quartz scheduler or trigger, and a simple isMasterNode boolean member for storing state. I'd then expose 2 [restricted-access] web service calls: makeMaster and makeSlave, which will call Scheduler.resume() or standby/pause, respectively.

Finall, the big question is how & with what you determine that another node has 'crashed'.

If you're using a hardware loadbalancer to manage this, you could configure it to call the 'makeMaster' WS on the new 'primary' node, which in turn calls Scheduler.resume() or similar.

hth

amir75
A: 

Thanks for the answer. Though I could not understand the reasoning for Mater or Slave in a load balancer. So here is the problem in a little more detail : I have two instances of Tomcat t1, t2 both sharing load for my web app equally, but running on two separate jvms. Since the war file deployed is the same on both instances the scheduler will kick off the same jobDetailBean method at the same time. This will cause a problem since the same method will be executed twice. Hope I was able to describe the problem better than before.

rabbit