我的作业在指定的时间运行,但每秒钟运行一次,例如,如果我将作业设置为在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...
将第一个*更改为0,并带有一个星星,您说的是“每秒”。
用0(或其他任何数字0-59代替)将使其在该“第二”而不是“所有它们”上运行。
@Scheduled(cron = "0 54 22 * * ?")
public void getCompaniess() {
System.out.println(new Date()+" > Running testScheduledMethod...");
}