工作中使用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 }