Spring - 在某个时间段安排任务
Spring - schedule task in some period of time
目前我正在使用 Spring 注释每 20 分钟安排一次我的任务:
@Scheduled(fixedRate = 1200000)
我想更改我的任务仅在凌晨 2 点到 5 点之间执行的时间表(仍然是每 20 分钟一次)。
Spring 调度器可以吗?或者有解决这个问题的最佳实践吗?
谢谢
@Scheduled 具有 'cron' 元素,因此您可以使用 cron
的全部功能
@Scheduled(cron = "0 0/20 2-5 * * ?")
0/20 -> 每 20 分钟一班
2-5 -> 凌晨 2 点到 5 点之间
目前我正在使用 Spring 注释每 20 分钟安排一次我的任务:
@Scheduled(fixedRate = 1200000)
我想更改我的任务仅在凌晨 2 点到 5 点之间执行的时间表(仍然是每 20 分钟一次)。
Spring 调度器可以吗?或者有解决这个问题的最佳实践吗?
谢谢
@Scheduled 具有 'cron' 元素,因此您可以使用 cron
的全部功能@Scheduled(cron = "0 0/20 2-5 * * ?")
0/20 -> 每 20 分钟一班
2-5 -> 凌晨 2 点到 5 点之间