Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Quartz to Schedule Single Job Across Multiple Stateless App Servers

I have a layer of identical app servers behind a load balancer. For operational reasons I have the constraint that the application configuration on both app servers must be identical so that nodes can easily be added and removed. All app servers share the same database. App servers are not/will not be clustered.

This has worked fine until now, but now I would like to have a scheduled job that executes on exactly one of the app servers. All app servers will run Quartz and have the same schedule for running jobs. The trigger will fire on every app server, but I would like only one app server to actually execute the job - essentially they all race to start and only one actually starts, the remaining app servers just ignore the job. The idea here is that if we lose an app server, another one would run the job instead, and if we add new app servers, they will take their turn at running jobs.

I was planning to do this by having a 'job lock' table in the database that all app servers would read prior to starting a job and only start if job is 'unlocked'. The app server that makes the update first to the table will essentially block others by updating the table to a running state/resetting it at the end of the job.

Before I build this, I'd appreciate some input from those with more experience of Quartz:

a) Can I hook this behaviour into Quartz so that it doesn't have to be done on a per job basis? I.e. developers can add new jobs without worrying about job locking as it is abstracted away.

b) Does Quartz provide any built in mechanisms to achieve something similar to above so I don't have to roll it myself?

Thanks!

like image 824
Scruffers Avatar asked Jul 12 '11 11:07

Scruffers


People also ask

How do you trigger multiple jobs in quartz scheduler?

If you want to schedule multiple jobs in your console application you can simply call Scheduler. ScheduleJob (IScheduler) passing the job and the trigger you've previously created: IJobDetail firstJob = JobBuilder.

What is the batch job scheduling system in quartz?

QuartzJobScheduling is an open-source job scheduling library. It has a rich set of features that can integrate into our Java applications virtually. We can integrate it with either a stand-alone application or the largest e-commerce system. Quartz is used for creating complex schedules having tens-of-thousands of jobs.

What is the use of quartz scheduler?

Quartz is an open source job-scheduling framework written entirely in Java and designed for use in both J2SE and J2EE applications. It offers great flexibility without sacrificing simplicity. You can create complex schedules for executing any job.


Video Answer


1 Answers

Do you think this will work for you? http://www.quartz-scheduler.org/documentation/quartz-2.3.0/configuration/ConfigJDBCJobStoreClustering.html Excerpt from the link

Clustering currently only works with the JDBC-Jobstore (JobStoreTX or JobStoreCMT), and essentially works by having each node of the cluster share the same database.

Load-balancing occurs automatically, with each node of the cluster firing jobs as quickly as it can. When a trigger's firing time occurs, the first node to acquire it (by placing a lock on it) is the node that will fire it.`

like image 172
Sap Avatar answered Sep 24 '22 02:09

Sap