我试图让我的代码基于Spring cron表达式按固定的时间表执行。我希望代码每天1:01:am执行。我尝试了以下表达式,但这并没有激发我。这里的语法有什么问题?
@Scheduled(cron = "0 1 1 ? * *") public void resetCache() { // ... }
尝试:
@Scheduled(cron = "0 1 1 * * ?")
你可以在下面的Spring论坛中找到示例模式:
* "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 8,10 * * *" = 8 and 10 o'clock of every day. * "0 0/30 8-10 * * *" = 8:00, 8:30, 9:00, 9:30 and 10 o'clock 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
Cron表达式由六个字段表示:
second, minute, hour, day of month, month, day(s) of week
(*)意味着匹配任何
(*)
*/X 表示“每个X”
*/X
?(“无特定值”)-在需要在允许使用字符的两个字段之一中指定某些内容而在另一个不允许使用的字段中指定内容时很有用。例如,如果我希望触发器在每月的某个特定日期(例如10号)触发,但是我不在乎一周中的哪一天,我会在当天输入“ 10”,月字段和“?” 在“星期几”字段中。
?