Quartz scheduler in cluster environment

匿名 (未验证) 提交于 2019-12-03 00:59:01

问题:

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

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!