gpt4 book ai didi

Java : Quartz scheduler - is there a way I can get next five runs of a scheduled job

转载 作者:行者123 更新时间:2023-12-02 04:50:04 26 4
gpt4 key购买 nike

是否有任何 API 可以提供接下来的 n 次 cron 表达式运行。

最佳答案

您可以这样计算下一次运行时间:

import org.springframework.scheduling.support.CronTrigger;
import org.springframework.scheduling.support.SimpleTriggerContext;

public static void main(String[] args) {
CronTrigger trigger = new CronTrigger("0 0 10 * * ?");
SimpleTriggerContext triggerContext = new SimpleTriggerContext();
Date testDate = new Date();
int i = 0;
while (i++ < 5) {
triggerContext.update(null, null, testDate);
testDate = trigger.nextExecutionTime(triggerContext);
System.out.println(testDate);
}
}

输出是:

    Wed Jun 05 10:00:00 CEST 2019
Thu Jun 06 10:00:00 CEST 2019
Fri Jun 07 10:00:00 CEST 2019
Sat Jun 08 10:00:00 CEST 2019
Sun Jun 09 10:00:00 CEST 2019

关于Java : Quartz scheduler - is there a way I can get next five runs of a scheduled job,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56451154/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com