简体   繁体   English

Spring Boot Job Scheduler fixedDelay和cron

[英]Spring Boot Job Scheduler fixedDelay and cron

I'm running a spring boot scheduled process that takes 5-10 seconds to complete. 我正在运行一个春季启动计划的过程,该过程需要5-10秒才能完成。 After it completes, 60 seconds elapse before the process begins again (Note that I'm not using fixedRate): 完成后,经过60秒钟,该过程才再次开始(请注意,我没有使用fixedRate):

@Scheduled(fixedDelay=60_000)

N ow, I want to limit it to run every minute Mon-Fri 9am to 5pm. 现在,我希望将其限制为从周一至周五上午9点到下午5点每分钟运行一次。 I can accomplish this with 我可以做到这一点

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

Problem here is that this acts similar to fixedRate - the process triggers EVERY 60 seconds regardless of the amount of time it took to complete the previous run... 这里的问题是,此行为类似于fixedRate-无论完成上一次运行花费的时间如何,该过程都会触发每60秒一次...

Any way to to combine the two techniques? 有什么方法可以结合这两种技术?

Try below: 请尝试以下方法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM