石英调度程序下次执行时间等于当前时间加上调度间隔。

huangapple go评论69阅读模式
英文:

Quartz Scheduler next execution time equal current time plus interval of scheduler

问题

我正在使用Quartz调度器,根据要求一切都运行得很完美。但有一件事我想要实现,那就是我希望我的作业的下一次执行将在**(currentFinishTime + intervalOfScheduler)**后触发。

具有30秒间隔的作业执行示例:

> Job-1-First-Executed 在 10-10-2020 18:30:05
> Job-1-Second-Executed 在 10-10-2020 18:30:35
> Job-1-Third-Executed 在 10-10-2020 18:31:05

所以,如果作业需要20秒来执行,那么下一次触发将在05+20+30 = 55时发生。不是在10-10-2020 18:30:35,而是在10-10-2020 18:30:55触发,其他执行也是如此...

注意:@DisallowConcurrentExecutionMyJobExecutor implements Job {public void execute(JobExecutionContext context){...}}已经实现。

请帮助我解决我的问题。

英文:

I am working with Quartz scheduler and everything work perfect according to the requirement. But there one thing that I want to implement and i.e. I want my next execution of job will trigger on (currentFinishTime + intervalOfScheduler)

Example of job execution with 30 seconds of interval:

> Job-1-First-Executed at 10-10-2020 18:30:05
> Job-1-Second-Executed at 10-10-2020 18:30:35
> Job-1-Third-Executed at 10-10-2020 18:31:05

So, here if the job takes 20 seconds to execute then next trigger will happen on 05+20+30 = 55. Instead of 10-10-2020 18:30:35, it will trigger at 10-10-2020 18:30:55 and same for other execution and so on...

Note: @DisallowConcurrentExecution and MyJobExecutor implements Job {public void execute(JobExecutionContext context){...}} are already implemented.

Please help me to solve my problem.

答案1

得分: 0

经过大量的研究,我已经实现了满足我的需求的解决方案。下面是代码部分:

if (是否包含执行时间) {
    final TriggerBuilder triggerBuilder = context.getTrigger().getTriggerBuilder();
    final Trigger newTrigger = triggerBuilder
        .withSchedule(SimpleScheduleBuilder.simpleSchedule()
            .withIntervalInSeconds(cpoPullJobData.getInterval())
            .repeatForever())
        .startAt(futureDate(interval/*例如30*/, DateBuilder.IntervalUnit.SECOND);)
        .build();
    context.getScheduler().rescheduleJob(context.getTrigger().getKey(), newTrigger);
}
英文:

After a lots of research, I have implemented my own solution which suffice my requirement. The code is mentioned below:

if(isExecutionTimeIncluded) {
    final TriggerBuilder triggerBuilder = context.getTrigger().getTriggerBuilder();
    final Trigger newTrigger = triggerBuilder
                  .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                  .withIntervalInSeconds(cpoPullJobData.getInterval())
                                .repeatForever())
                  .startAt(futureDate(interval/*eg.30*/, DateBuilder.IntervalUnit.SECOND);)
                  .build();
    context.getScheduler().rescheduleJob(context.getTrigger().getKey(), newTrigger);
}

huangapple
  • 本文由 发表于 2020年10月6日 21:11:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/64226533.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定