Spring Boot Job Scheduler fixedDelay和cron

问题描述 投票:0回答:1

我正在运行一个弹簧启动计划过程,需要5-10秒才能完成。完成后,再过程开始60秒(注意我没有使用fixedRate):

@Scheduled(fixedDelay=60_000)

N ow,我想限制它在周一至周五上午9点到下午5点每分钟运行一次。我可以用这个完成

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

这里的问题是这个行为类似于fixedRate - 无论完成上一次运行所花费的时间多少,该过程每60秒触发一次......

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

java cron scheduler
1个回答
0
投票

试试以下:

@Schedules({ 
  @Scheduled(fixedRate = 1000), 
  @Scheduled(cron = "* * * * * *")
})
© www.soinside.com 2019 - 2024. All rights reserved.