[英]Quartz Scheduler firing cron job on all nodes in clustered mode
I have an application that uses Quartz as a job scheduler.我有一个使用 Quartz 作为作业调度程序的应用程序。 There are two scenarios
有两种情况
I run two instances of my application.我运行我的应用程序的两个实例。 Both are set to clustered mode and both have instanceId set to "AUTO."
两者都设置为集群模式,并且都将 instanceId 设置为“AUTO”。
These are my observations:这些是我的观察:
Both instances of the application boots up and connects to the db.应用程序的两个实例都启动并连接到数据库。 Both report that they are clustered and connected to the db successfully.
两者都报告它们已成功集群并连接到数据库。
When I schedule a job based on scenario 1, at the time of job execution only a single application executes the job.当我根据场景 1 安排作业时,在作业执行时只有一个应用程序执行作业。
Scenario 2, ie the cron job that executes every 10 seconds, is being executed by both applications at the same time.场景 2,即每 10 秒执行一次的 cron 作业,正在由两个应用程序同时执行。
I look at the qrtz tables in the db.我查看数据库中的 qrtz 表。 There is only one job and one trigger for the cron job.
cron 作业只有一个作业和一个触发器。
I also observe in the qrtz db "scheduled state" table that both instances of the application are consistently checking in.我还在 qrtz db“计划状态”表中观察到应用程序的两个实例都在持续签入。
Here is how I setup the cron job:这是我设置 cron 作业的方法:
val myCronJob = newJob(MyCronJob::class.java)
.withIdentity("cronjob", "cronJobGroup")
.build()
val trigger = newTrigger()
.withIdentity("cronjob", "cronJobGroup")
.startNow()
.withSchedule(simpleSchedule()
.withMisfireHandlingInstructionIgnoreMisfires()
.withIntervalInSeconds(10)
.repeatForever())
.build()
Any help or guidance would be much appreciated!任何帮助或指导将不胜感激!
I think you could use the @DisallowConcurrentExecution annotation on your job class.我认为您可以在工作 class 上使用 @DisallowConcurrentExecution 注释。
From documentation: An annotation that marks a Job class as one that must not have multiple * instances executed concurrently (where instance is based-upon a JobDetail * definition - or in other words based upon a JobKey).来自文档:将作业 class 标记为不能同时执行多个 * 实例的注释(其中实例基于 JobDetail * 定义 - 或换句话说基于 JobKey)。
org.quartz.jobStore.isClustered = true org.quartz.jobStore.isClustered = true
ensures proper row locks are applied to the trigger before picking it, if that property was false both instances can pick up one trigger.确保在选择触发器之前将正确的行锁应用于触发器,如果该属性为假,则两个实例都可以选择一个触发器。
http://www.quartz-scheduler.org/documentation/quartz-1.8.6/configuration/ConfigJDBCJobStoreClustering.html http://www.quartz-scheduler.org/documentation/quartz-1.8.6/configuration/ConfigJDBCJobStoreClustering.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.