在Spring中访问计划任务
问题描述:
我在 Spring的任务计划程序中安排了几项任务:
I have a couple of tasks scheduled within Spring's task scheduler:
<task:scheduled-tasks>
<task:scheduled ref="task1" method="run"
cron="0 0 */0 * * *" />
<task:scheduled ref="task2" method="run"
cron="0 0 */30 * * *" />
</task:scheduled-tasks>
<task:scheduler id="scheduler" pool-size="10" />
如何访问计划任务列表并检索应用程序上下文中的元信息(例如下一个执行时间)?
How can I access a list of scheduled tasks and retrieve meta-information (e.g the next execution time) from within the application context?
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
ThreadPoolTaskScheduler scheduler = (ThreadPoolTaskScheduler)context.getBean("scheduler");
//... how to continue from here?
答
Spring中没有公共API来执行此操作。
There is no public API in Spring to do this.
相关:
- How are Spring <task:scheduled> objects represented at runtime?