首页 > 解决方案 > Spring Boot Job Scheduler fixedDelay 和 cron

问题描述

我正在运行一个需要 5-10 秒才能完成的 Spring Boot 计划进程。完成后,60 秒后该过程再次开始(请注意,我没有使用 fixedRate):

@Scheduled(fixedDelay=60_000)

现在,我想限制它在周一至周五上午 9 点到下午 5 点每分钟运行一次。我可以做到这一点

@Scheduled(cron="0 * 9-16 ? * MON-FRI")

这里的问题是它的行为类似于 fixedRate - 该过程每 60 秒触发一次,而不管完成上一次运行所花费的时间......

有什么方法可以结合这两种技术?

标签: javacronscheduler

解决方案


试试下面:

@Schedules({ 
  @Scheduled(fixedRate = 1000), 
  @Scheduled(cron = "* * * * * *")
})

推荐阅读