SpringMVC 自帶Task 實現並行 & 串行


與Quarz相比,SpringMVC提供的任務調度相對簡單,通過配置文件即可實現Job的定時調度,但是任務比較多的話,可能不僅涉及到並行,相關聯的Job還有串行的需求。

可以通過配置多個task:scheduler 實現並行和串行,以應對復雜一些的Job。

 1     <task:scheduler id="schedulerA" pool-size="4" />
 2     <task:scheduled-tasks scheduler="schedulerA">
 3         <task:scheduled ref="jobSchedule1" method="background" cron="0 0 10,22 * * ?" />
 4         <task:scheduled ref="jobSchedule2" method="background" cron="0 0 2,7,19 * * ?" />
 5         <task:scheduled ref="jobSchedule3" method="background"    cron="0 */30 * * * ?" />
 6         <task:scheduled ref="jobSchedule4" method="background"    cron="0 */30 * * * ?" />
 7     </task:scheduled-tasks>
 8     
 9     <task:scheduler id="schedulerB" pool-size="1" />
10     <task:scheduled-tasks scheduler="schedulerB">
11         <task:scheduled ref="jobSchedule1" method="background" cron="0 0 8 * * ?" />
12         <task:scheduled ref="jobSchedule2" method="background" cron="0 0 8 * * ?" />
13         <task:scheduled ref="jobSchedule3" method="background"    cron="0 */30 * * * ?" />
14         <task:scheduled ref="jobSchedule4" method="background"    cron="0 */30 * * * ?" />
15     </task:scheduled-tasks>

其中,schedulerA中的4個Job是並行的,schedulerB中的4個Job是串行的,schedulerA整體和schedulerB整體是並行的。


免責聲明!

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



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