Spring 調度任務@scheduled學習總結


工作中使用Scheduled標簽,非常的便於開發,但是此標簽以為不靈活,沒法動態設置間隔時間,查閱標簽后發現,可以設定動態時間到props中,非常方便

 

@PropertySource("classpath:root/test.props")
然后修改你的@Scheduled(cron="0/5 * *  * * ? ") 為 @Scheduled(cron="${jobs.schedule}") 
最后test.props 添加 jobs.schedule = 0/5 * *  * * ?

或者將Scheduled配置到xml中。
對於標簽的使用,查閱資料復制如下:

以下為復制粘貼內容:

轉自:http://blog.csdn.net/kongling16688/article/details/45918833

 

1.initialDelay :初次執行任務之前需要等待的時間

@Scheduled(initialDelay =5000)
public void doSomething() { }

 

2.fixedDelay:每次執行任務之后間隔多久再次執行該任務。

@Scheduled(fixedDelay=5000)
public void doSomething() { // something that should execute periodically }

 

3.fixedRate:執行頻率,每隔多少時間就啟動任務,不管該任務是否啟動完成

@Scheduled(fixedRate=5000)
public void doSomething() { }

4.cron=“”設置時分秒等具體的定時,網上很很多相關列子。

例如:轉:http://blog.csdn.net/kkdelta/article/details/7238581

 

@Scheduled(cron="*/5 * * * * MON-FRI")
public void doSomething() { // something that should execute on weekdays only }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM