2017-02-24 26 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