【问题标题】:Spring scheduled cron job running too many times春季计划的 cron 作业运行次数过多
【发布时间】:2020-06-25 00:36:57
【问题描述】:

我的作业在指定的时间运行,但它在指定的时间每秒运行一次,例如,如果我将作业设置为在 22:54 运行,它将从 22:54:00 到 22:54 每秒运行一次: 59.我希望它在指定的时间只运行一次......非常感谢任何帮助

我的代码:

@Scheduled(cron = "* 54 22 * * ?")
    public void getCompaniess() {
         System.out.println(new Date()+" > Running testScheduledMethod...");

    }

输出: Thu Mar 12 22:54:00 GMT 2020 > Running testScheduledMethod... Thu Mar 12 22:54:01 GMT 2020 > Running testScheduledMethod... ..... Thu Mar 12 22:54:59 GMT 2020 > Running testScheduledMethod...

【问题讨论】:

    标签: spring-boot cron spring-scheduled


    【解决方案1】:

    将第一个 * 更改为 0,用星号表示“每秒”。

    将其替换为 0(或任何其他数字 0-59)将使其在“秒”而不是“全部”上运行。

    【讨论】:

    • 这很有效,我一直在努力解决问题。谢谢
    【解决方案2】:
    @Scheduled(cron = "0 54 22 * * ?")
    public void getCompaniess() {
        System.out.println(new Date()+" > Running testScheduledMethod...");
    }
    

    【讨论】:

    猜你喜欢
    • 2010-09-12
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-22
    • 2019-07-23
    • 1970-01-01
    相关资源
    最近更新 更多