quartz禁止一个工作任务还没执行完,下一个工作(同jobkey)就开始执行的方法

本文介绍如何在Quartz调度器中使用@DisallowConcurrentExecution注解来限制特定任务的并发执行,确保同一时间只有一个实例运行,同时允许不同实例间的并行处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在job接口实现类上添加@DisallowConcurrentExecution注解

@DisallowConcurrentExecution
public class IncrCrawlJob implements Job {

    /** logger */

note:

  • 该时间段应该执行几个任务还是会执行几个任务,即使上一个任务执行完毕后已经超过该时间段

参考资料:

@DisallowConcurrentExecution is an annotation that can be added to the Job class that tells Quartz not to execute multiple instances of a given job definition (that refers to the given job class) concurrently.
Notice the wording there, as it was chosen very carefully. In the example from the previous section, if “SalesReportJob” has this annotation, than only one instance of “SalesReportForJoe” can execute at a given time, but it can execute concurrently with an instance of “SalesReportForMike”. The constraint is based upon an instance definition (JobDetail), not on instances of the job class. However, it was decided (during the design of Quartz) to have the annotation carried on the class itself, because it does often make a difference to how the class is coded.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值