我在配置文件中定义了各种调度程序,如下所示:
<task:executor id="xxxxxExecutor" pool-size="${async.executor.pool.size}"/>
<task:scheduler id="xxxxwwwScheduler" pool-size="1" />
<task:scheduler id="qqqqSchedular" pool-size="1" />
<task:scheduler id="lastScheduler" pool-size="1" />
我的 Controller 已通过 @Controller 注释进行注释。如何在 Spring 中的 @Scheduled
注释中指定特定的 Scheduler
?
附:我正在尝试使用 @Scheduled
注释在 Controller 中安排一个方法。
最佳答案
不幸的是,使用多个调度程序并通过@Scheduled
注释指向它们不可能。
但是,如果您确实需要这种灵 active ,则可以在 XML 中定义作业:
<task:scheduled-tasks scheduler="myScheduler">
<task:scheduled ref="beanA" method="methodA" fixed-delay="5000"/>
</task:scheduled-tasks>
这允许您指定需要使用的调度程序的确切 ID,然后简单地引用实际任务。
希望这有帮助。
关于java - 如何在 Spring MVC Controller 中安排方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27589198/