venkat
venkat

Reputation: 509

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

Upvotes: 41

Views: 52591

Answers (1)

Apostolos Emmanouilidis
Apostolos Emmanouilidis

Reputation: 7197

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.

Upvotes: 52

Related Questions