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

Tes*_*ult 6 cron spring-scheduled spring-boot

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

我的代码:

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

    }
Run Code Online (Sandbox Code Playgroud)

输出: 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...

Wil*_*ung 7

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

将其替换为 0(或 0-59 之间的任何其他数字)将使其在该“第二”而不是“所有”上运行。