【问题标题】:Spring Boot scheduled task running for entire hour rather than at the hourSpring Boot 计划任务运行一小时而不是一小时
【发布时间】:2018-08-13 16:13:31
【问题描述】:

这里是 Spring Boot。我有以下计划任务:

@Component
public class AdminWatchdog {
    @Autowired
    private EmailService emailService;

    // Ctors, getters & setters here

    @Scheduled(cron = "'* * */12 * * *")
    public void runReports() {
        // Doesn't matter what it does, really
    }
}

当我运行它时,它似乎每分钟或每秒触发一次(根据日志无法判断)在每天的第 12 个小时的整个持续时间内! p>

我只希望这个任务在每天中午(12 点)运行一次。 Spring cron 是否配置不正确,或者我的应用程序中可能发生了其他事情?

【问题讨论】:

    标签: spring-boot cron scheduled-tasks


    【解决方案1】:

    您的 cron 不正确。为了每天中午运行你的工作,使用这个

    "0 0 12 * * ?"
    

    如果你理解每个字符代表什么,这个表达式是非常自我解释的

         0          0        12       *            *           ? 
      <second> <minute> <hour> <day-of-month> <month> <day-of-week>
    

    供您参考。您可以使用 http://www.cronmaker.com/ 之类的工具来设计您的 cron

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-24
      • 2013-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多