2014-12-21 54 views
0

我在配置文件中定义的各种调度如下:如何在弹簧MVC控制器中调度方法?

<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被注释。如何在Spring中的@Scheduled注释中指定特定的Scheduler

p.s.我正在尝试使用@Scheduled注释在控制器中安排一种方法。

+2

为什么你需要安排在控制器中?为什么你需要在你的web层中的处理方法?您不能在注释中指定特定的调度程序,在'task:annotation-driven'上指定的调度程序是始终使用的调度程序。 –

回答

1

使用多个调度程序并通过@Scheduled注释指向它们是不幸的不可能

但是,如果你真的需要这种灵活性,您可以在XML定义作业:

<task:scheduled-tasks scheduler="myScheduler"> 
    <task:scheduled ref="beanA" method="methodA" fixed-delay="5000"/> 
</task:scheduled-tasks> 

这允许你指定你需要使用调度的确切ID,然后简单地引用实际任务。

希望这会有所帮助。