2017-02-24 24 views
0

嗨我想cronjob将在春季运行,但我也需要确保它们不会重叠时运行是可能的。使用Spring启动5.1春季@计划与cron但没有重叠crons

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

这显然失败是有一些方法来获得此

+0

是的,并且发布的代码正如你所期望的那样[这里](http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/注释/ Scheduled.html#fixedDelay--) –

回答

0

,而不是配置的非重叠的cron的,你可以检查以前的运行方式是否已经完成,若没有,退出你的run()函数。

2

默认情况下,spring使用单线程Executor。所以没有两个@计划任务会重叠。

+0

Word for word copy从https://stackoverflow.com/questions/24033208/how-to-prevent-overlapping-schedules-in-spring – Kong