Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quartz scheduler in cluster environment

I am using

SchedulerFactory schedulerFactory = new StdSchedulerFactory(); scheduler = schedulerFactory.getScheduler(); scheduler.start(); Trigger asapTrigger = getAsapTrigger(); JobDetail asapJob = getAsapJobDetails(); scheduler.scheduleJob(asapJob, asapTrigger); 

This is working but when I go for cluster environment, 2 threads are running for the same job.

I am using annotations not properties file. I want to run only one thread. Can someone help on this. How to configure?

my code almost look like : http://k2java.blogspot.com/2011/04/quartz.html

like image 767
venkat Avatar asked Sep 27 '12 16:09

venkat


People also ask

What is quartz clustering?

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.

What is Quartz Scheduler used for?

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 Quartz Scheduler in Java?

Overview. 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.


1 Answers

You have to configure Quartz to run in a clustered environment. Clustering currently only works with the JDBC jobstore, and works by having each node of the cluster to share the same database.

  • Set the org.quartz.jobStore.isClustered property to true if you have multiple instances of Quartz that use the same set of database tables. This property is used to turn on the clustering features.
  • Set the org.quartz.jobStore.clusterCheckinInterval property (milliseconds) which is the frequency at which this instance checks in with the other instances of the cluster.
  • Set the org.quartz.scheduler.instanceId to AUTO so that each node in the cluster will have a unique instanceId.

Please note that each instance in the cluster should use the same copy of the quartz.properties file. Furthermore if you use clustering on separate machines ensure that their clocks are synchronized.

For more information check the official documentation which contains a sample properties file for a clustered scheduler.

like image 128
Apostolos Emmanouilidis Avatar answered Sep 29 '22 07:09

Apostolos Emmanouilidis