Spring 计划的 cron 作业 运行 次数太多

Spring scheduled cron job running too many times

我的工作是在指定的时间 运行ning,但它在指定的时间每隔一秒 运行ning,例如,如果我在 [=20] 将工作设置为 运行 =] 它会从 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...

把第一个*改成0,你说的是星号"every second"。

将其替换为 0(或任何其他数字 0-59)将在 "second" 上显示 运行 而不是 "all of them"。

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