Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quartz Scheduler: Trigger some jobs on every cluster node and some only once per cluster

I am using Quartz Scheduler as a Spring bean in a clustered environment.

I have some jobs annotated with @NotConcurrent and they are running once per cluster (i.e. only in one node, only in one thread).

Now I need to run one job on every node of the cluster. I removed the @NotConcurrent annotation, but it only run on every thread on one machine. It does not get fired on other nodes.

What should I annotate the job with?

Example: Job1 NotConcurrent annotated is scheduled at midnight => It fires only on 1 machine every midnight. Job2 annotated scheduled at midnight => It fire on every machine every midnight.

Thank you.

like image 411
Michaelsoft Avatar asked May 14 '14 21:05

Michaelsoft


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

How does Quartz clustering work?

Quartz's clustering features bring both high availability and scalability to your scheduler via fail-over and load balancing functionality. 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.

How does Quartz trigger work?

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.

What is trigger group in Quartz?

Trigger - a component that defines the schedule upon which a given Job will be executed. JobBuilder - used to define/build JobDetail instances, which define instances of Jobs.


1 Answers

AFAIK Quartz job are always executed on a single node that is picked by Quartz. The @NonConcurrent annotation only prevents Quartz from executing the same job concurrently on a particular node.

In other words, you cannot make Quartz execute a job on multiple nodes concurrently. It always picks a single node to execute the job on.

To realize what you describe, you may need multiple jobs (using the same job class and without associated triggers). Then you will need to implement some sort of an orchestrator job that would remotely connect, e.g. via JMX or RMI, to individual nodes and trigger the jobs manually.

You may want to check our product QuartzDesk (www.quartzdesk.com) that provides a web-service that provides a single-endpoint through which you can connect to individual Quartz scheduler instances and, for example, trigger jobs on them.

like image 199
Jan Moravec Avatar answered Sep 21 '22 00:09

Jan Moravec