简体   繁体   English

春季@安排了cron,但没有重叠的cron

[英]Spring @scheduled with cron but no overlapping crons

Hi I would like A cronjob to be run within spring but I also need to make sure that they don't overlap when running is this possible. 嗨,我希望A cronjob在春季内运行,但我还需要确保在运行时它们不会重叠。 Using spring boot 5.1 使用Spring Boot 5.1

@Scheduled(cron="${con}", fixedDelay = 5000)
 public void run(){
     some method
 }

this obviously fails is there some way to obtain this 这显然失败了,有某种方法可以做到这一点

By default, spring uses a single-threaded Executor. 默认情况下,spring使用单线程执行器。 so no two @Scheduled tasks will ever overlap. 因此,没有两个@Scheduled任务会重叠。

您可以检查先前的run方法是否已完成,而不是配置不重叠的cron,如果尚未完成,则退出run()函数。

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

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