2015/04/26

Spring Task 參考筆記

目標:希望在 Spring Web App 啟動後,能夠固定時間做某個特定的 Task

這篇說明如何做基本的設定,可採用 Annotation 或是 XML 的設定方式
http://howtodoinjava.com/2013/04/23/4-ways-to-schedule-tasks-in-spring-3-scheduled-example/

這篇說明是否應該同時使用 @Async 跟 @Scheduled 兩個 Annotation
http://stackoverflow.com/questions/14623092/using-spring-scheduled-and-async-together

如果 Scheduled 時程很短,可能會造成 deadlock,因為每次 invoke 一個 method 的時候就會產生一個新的 Thread。

其他有人提到引入其他 Library 的解法
http://www.quartz-scheduler.org/

其他參考

## Spring Cron Format

second, minute, hour, day of month, month, day(s) of week
* "0 0 * * * *" = the top of every hour of every day.
* "*/10 * * * * *" = every ten seconds.
* "0 0 8-10 * * *" = 8, 9 and 10 o'clock of every day.
* "0 0/30 8-10 * * *" = 8:00, 8:30, 9:00, 9:30 and 10 o'clock every day.
* "0 0 9-17 * * MON-FRI" = on the hour nine-to-five weekdays
* "0 0 0 25 12 ?" = every Christmas Day at midnight

No comments:

Post a Comment