2014-12-21 51 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,然後簡單地引用實際任務。

希望這會有所幫助。