在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.