防止由特定触发器触发的实例的并发执行
@DisallowConcurrentExecution 注解可以防止特定作业的作业实例的并发执行,但是是否可以防止使用特定触发器触发的作业的并发执行?
The @DisallowConcurrentExecution
annotation prevents the concurrent execution of job instances of a specific job, but is it possible to prevent concurrent execution of jobs fired with a specific trigger?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用自定义 TriggerListener 来实现此类限制,该自定义 TriggerListener 会否决作业执行并重新安排触发器以供稍后执行,等等。
否则,您可能只想复制要由您的特定触发器解雇的作业。
You could possibly implement such a restriction with a custom TriggerListener that vetos the job execution and rescheduled the trigger for a later date, or some such.
Otherwise you may just want to make a copy of the job to be fired by your particular trigger.
根据 Quartz Scheduler 的 Javadoc,
@DisallowConcurrentExecution
注解可以防止基于唯一的JobKey
的作业实例的并发执行。Javadoc 中没有其他注释具有与触发器类似的功能。
那么唯一的另一种可能性是定义一个自定义的JobKey - 但是该类是final 的。
太长了;不,如果不进行自己的同步,您就无法做到这一点。
According to the Javadoc of Quartz Scheduler, the
@DisallowConcurrentExecution
annotation prevents concurrent execution of job instances based on the uniqueJobKey
.There are no other annotations in the Javadoc that have a similar function for
Triggers
.Then the only other possibility would be to define a custom
JobKey
- however the class isfinal
.TLDR; No you can't do it without rolling your own synchronisation.