简体   繁体   中英

How do I schedule a method in a spring MVC controller?

I have defined various scheduler in my configuration file as follows:

<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" />

My controller has been annotated via @Controller annotation. How do I specify a particular Scheduler in @Scheduled annotation in Spring?

ps I am trying to schedule a method in a controller using @Scheduled annotation.

Using multiple schedulers and pointing to them via the @Scheduled annotation is unfortunately not possible .

However, if you really do need that flexibility, you can define the jobs in XML:

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

That allows you to specify the exact id of the scheduler you need to use, and then simply reference the actual task.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM