在 Quartz 调度器中使用 @DisallowConcurrentExecution [英] Using @DisallowConcurrentExecution in Quartz scheduler

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

问题描述

如果这个问题太幼稚,我很抱歉,我期望作业被调度,以便它一个接一个地执行,而不是并行执行.它只执行一次.

I am sorry if this question is too naive, I am expecting the jobs to be scheduled so that it executes one by one, and not parallely.It is executed only once.

从文档中,@DisallowConcurrentExecution 是

From docs, @DisallowConcurrentExecution is

  • 将 {@link Job} 类标记为不能同时执行多个实例的注释(其中实例基于 {@link JobDetail} 定义 - 或者换句话说,基于 {@link JobKey}).

但是当我使用相同的 JobKey 安排工作时,我得到了无法安排作业 org.quartz.ObjectAlreadyExistsException

But when I schedule a job with same JobKey, I am getting Failed to schedule a job org.quartz.ObjectAlreadyExistsException

如果我生成一个不同的 JobKey,它不会注意到 @DisallowConcurrentExecution 并且该作业将并行执行(如文档中所述).

If I generate a different JobKey, it is not heeding to @DisallowConcurrentExecution and the job is getting executed in parallel(as mentioned in docs).

请建议我如何实现这一点,任何指针都会真正有帮助!

Please suggest how can I achieve this, any pointers would really help!

PS:我不知道将安排的工作.所以,如果作业已经在运行,我需要一些方法来动态链接作业.

PS: I do not know the jobs that would be scheduled. So, I need some method to dynamically link up the jobs,if the job is already running.

推荐答案

Same JobKey = 相同的工作.
不同的 JobKey = 不同的工作.

Same JobKey = same job.
Different JobKey = different job.

Quartz 不会让您多次使用相同的 JobKey,因为那将是两个具有相同密钥的作业.就像有两个具有相同 ID 的用户一样.

Quartz won't let you use the same JobKey more than once because that'd be two jobs with the same key. Like having two users with the same ID.

你需要做的是为同一个JobKey安排不同的JobTrigger.

What you need to do is schedule different JobTriggers for the same JobKey.

@DisallowConcurrentExecution 避免了 相同 作业的重叠执行.如果您使用不同的 JobKey,它就不再是同一个工作,因此注释没有任何作用.但是对于具有多个 JobTrigger 的给定 JobKey@DisallowConcurrentExecution 将阻止触发器启动新的作业执行,如果前一个还没完.

@DisallowConcurrentExecution avoids overlapping executions of the same job. If you use a different JobKey, it's not the same job anymore, so the annotation doesn't have any effect. But for a given JobKey with several JobTriggers, @DisallowConcurrentExecution will keep the triggers from launching a new execution of the job, if the previous one hasn't finished yet.

我建议看看 Quartz 的文档以更深入地理解上述概念.

I suggest having a look at Quartz's documentation to get a deeper understanding of the above concepts.

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

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