Spring计划的Cron作业运行太多次

问题描述 投票:1回答:2

我的作业在指定的时间运行,但每秒钟运行一次,例如,如果我将作业设置为在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
2个回答
1
投票

将第一个*更改为0,并带有一个星星,您说的是“每秒”。

用0(或其他任何数字0-59代替)将使其在该“第二”而不是“所有它们”上运行。


0
投票
@Scheduled(cron = "0 54 22 * * ?")
public void getCompaniess() {
    System.out.println(new Date()+" > Running testScheduledMethod...");
}
© www.soinside.com 2019 - 2024. All rights reserved.