2014-12-08 110 views
0

我知道關於彈簧任務調度程序使用固定延遲工作使用@Scheduled(fixedDelay=1000)@Scheduled(fixedRate=2000)但是如果我想知道15分鐘後執行某些任務。有沒有這樣的Trigger,我可以使用每個功能? 場景像:如果我想15分鐘後,執行它,當我15分鐘後excecuting我會決定我是否想15分鐘後不再執行延遲的每15分鐘春天任務計劃程序

回答

1

您需要使用intialDelay沿fixedDelayfixedRate

@Scheduled(fixedDelay = 2000 , initialDelay = 900000) // first execution would be after 900000 ms or 15 minutes 

請參見相關文檔here

+0

如果我想15分鐘後,執行它,當我15分鐘後excecuting我會決定我是否想15分鐘後不再執行了每15分鐘的延遲.. – MasterCode 2014-12-08 10:03:42

+1

開箱即用的彈簧'@ Scheduled'在這種情況下不會有任何幫助。您需要使用[ScheduledExecutorService](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html)探索 – 2014-12-08 10:15:13

+0

也考慮使用該方案更新您的問題或詢問新問題;因爲我的回答涵蓋了你在當前問題中提到的場景。 – 2014-12-08 10:17:44