集群环境中的 Quartz 调度器 [英] Quartz scheduler in cluster environment

查看:72
本文介绍了集群环境中的 Quartz 调度器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

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

这是可行的,但是当我进入集群环境时,有 2 个线程正在为同一个作业运行.

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?

我的代码几乎看起来像:http://k2java.blogspot.com/2011/04/quartz.html

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

推荐答案

您必须配置 Quartz 才能在集群环境中运行.集群目前仅适用于 JDBC 作业存储,并且通过让集群的每个节点共享相同的数据库来工作.

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.

  • 如果您有多个使用同一组数据库表的 Quartz 实例,请将 org.quartz.jobStore.isClustered 属性设置为 true.此属性用于打开聚类功能.
  • 设置 org.quartz.jobStore.clusterCheckinInterval 属性(毫秒),这是此实例与集群的其他实例签入的频率.
  • org.quartz.scheduler.instanceId 设置为 AUTO,以便集群中的每个节点都具有唯一的 instanceId.
  • 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.

请注意集群中的每个实例都应该使用quartz.properties 文件的相同副本.此外,如果您在不同的机器上使用集群,请确保它们的时钟同步.

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.

这篇关于集群环境中的 Quartz 调度器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆