【发布时间】:2015-08-14 11:48:40
【问题描述】:
我有一个 java 中的 Spring Boot 应用程序,我需要在每天午夜运行一些计划任务,从 6 月 15 日到 8 月 15 日
@Scheduled(cron = "0 0 0 15-30 5 ?") // Midnight every day from 15th June until end of month
public void sendReminderEmailsJune() {
doStuff();
}
@Scheduled(cron = "0 0 0 * 6 ?") // Every day in July
public void sendReminderEmailsJuly() {
doStuff();
}
@Scheduled(cron = "0 0 0 1-15 7 ?") // The first day in August to 15th August
public void sendRemindersEmailsAugust() {
doStuff();
}
有没有更好的方法来做到这一点,所以我不需要 3 个单独的 @Scheduled 函数?
【问题讨论】:
标签: spring-boot scheduled-tasks