Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring quartz/cron jobs in a distributed environment

I have a fleet of about 5 servers. I want to run an identical Spring/Tomcat app on each machine.

I also need a particular task to be executed every ten minutes. It should only run on one of the machines. I need some sort of election protocol or other similar solution.

Does Spring or Quartz have any sort of built-in distributed cron solution, or do I need to implement something myself?

like image 637
Brandon Yarbrough Avatar asked Apr 25 '11 19:04

Brandon Yarbrough


People also ask

Is Quartz scheduler distributed?

Quartz is distributed as a small java library (. jar file) that contains all of the core Quartz functionality. The main interface (API) to this functionality is the Scheduler interface. It provides simple operations such as scheduling/unscheduling jobs, starting/stopping/pausing the scheduler.

How do you schedule multiple jobs using Quartz?

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. Create<FirstJob>() .

How does Quartz Scheduler work internally?

Quartz scheduler allows an enterprise to schedule a job at a specified date and time. It allows us to perform the operations to schedule or unschedule the jobs. It provides operations to start or stop or pause the scheduler. It also provides reminder services.

Where do you put Quartz properties?

properties on the classpath. If you're building a web application (i.e. in the form of a . war file) that includes Quartz, you will likely want to place the quartz. properties file in the WEB-INF/classes folder in order for it to be on the classpath.


1 Answers

Hazelcast has a distributed executor framework which you can use to run jobs using the JDK Executor framework (which, by the way, is possibly more testable than horrid Quartz... maybe). It has a number of modes of operation, including having it pick a single node "at random" to execute your job on.

See the documentation for more details

like image 146
dty Avatar answered Nov 01 '22 06:11

dty