春季预定任务

时间:2014-08-20 22:08:46

标签: spring task spring-scheduled

我试图将Spring计划任务用于我的预定作业,我有一个为多个任务执行程序配置的调度程序,如下所示

<task:scheduled-tasks scheduler="ABCTaskScheduler">
    <task:scheduled ref="ABCTaskExecutor" method="execute"
            cron="some_expression_1" />     
    <task:scheduled ref="DEFTaskExecutor" method="execute"
            cron="some_expression_1" /> 
</task:scheduled-tasks>

我的问题是如何使任务执行程序列表动态化,以便每次我必须添加新的任务执行程序时都不必更改spring配置。

1 个答案:

答案 0 :(得分:0)

您可以将TaskScheduler(例如ThreadPoolTaskScheduler)配置为简单的bean,然后使用以下代码安排执行程序:

scheduler.schedule(myTask, new CronTrigger("* 15 9-17 * * MON-FRI"));

请参阅Spring documentation了解完整的纲要。

相关问题