cron 作业是否重叠?

Do cron jobs overlap?

我有一个 cron Quartz 触发器作业,每 30 秒执行一次,模式如下:

0/30 * * * * ?

使用这种模式,如果我的作业花费超过 30 秒来完成执行,是否会触发下一个流程并与第一个流程重叠?

我在某处读到,您可以编写一个模式以在上一个过程完成 n 秒后启动 cron 触发器,但找不到以这种方式编写我的作业的确切答案。

您可能需要的是有状态的作业实施。您需要实现 StatefulJob 接口而不是 Job

文档中说

如果作业是有状态的,并且触发器在作业已经执行时尝试 'fire',触发器将阻塞(等待)直到上一次执行完成。

您可以在此处找到更多详细信息 link http://www.quartz-scheduler.org/documentation/quartz-1.x/tutorials/TutorialLesson03

StatefulJob 可能是我需要的 Job,但是根据 this and this 答案,面对这个问题的正确方法是:

石英 2

在 Quartz 2.0 版本中,StatefulJob 已被弃用。现在建议改用注解:

@DisallowConcurrentExecution
public class YourJob implements org.quartz.Job {
    void execute(JobExecutionContext context) {/*implementation omitted*/}
}

解释:

@DisallowConcurrentExecution: multiple instances of the job will not be allowed to run concurrently (consider a case where a job has code in its execute() method that takes 34 seconds to run, but it is scheduled with a trigger that repeats every 30 seconds).