您能否验证我的所有作业是否都已正确配置?我不确定年度任务
//Every Hour
@Scheduled(cron = "0 0 * * * * ")
public void taskHour() {}
//Every Day
@Scheduled(cron = "0 0 0 * * *")
public void taskDay() {}
//EveryMonth
@Scheduled(cron = "0 0 0 1 * *")
public void taskMonth() {}
//Every Year
@Scheduled(cron = "0 0 0 1 1 *")
public void taskYear() {}
最佳答案
The pattern is a list of six single space-separated fields: representing second, minute, hour, day, month, weekday. Month and weekday names can be given as the first three letters of the English names.
Example patterns:
"0 0 * * * *" = the top of every hour of every day. "*/10 * * * * *" = every ten seconds. "0 0 8-10 * * *" = 8, 9 and 10 o'clock of every day. "0 0 6,19 * * *" = 6:00 AM and 7:00 PM every day. "0 0/30 8-10 * * *" = 8:00, 8:30, 9:00, 9:30, 10:00 and 10:30 every day. "0 0 9-17 * * MON-FRI" = on the hour nine-to-five weekdays "0 0 0 25 12 ?" = every Christmas Day at midnight
所以分析你的代码
//Every Hour
@Scheduled(cron = "0 0 * * * * ")
public void taskHour() {}
每天每个小时的顶部。 - 好的
//Every Day
@Scheduled(cron = "0 0 0 * * *")
public void taskDay() {}
每天的顶部。 - 好的
//EveryMonth
@Scheduled(cron = "0 0 0 1 * *")
public void taskMonth() {}
安排在该月的第一天。 - 好的
//Every Year
@Scheduled(cron = "0 0 0 1 1 *")
public void taskYear() {}
计划在一月的第一天进行,因此每年进行一次。 - 好的
所以您的代码满足您的要求。
关于java - Spring Cron验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42989015/