简体   繁体   English

如何在Spring MVC控制器中安排方法?

[英]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. 我的控制器已通过@Controller注释进行了注释。 How do I specify a particular Scheduler in @Scheduled annotation in Spring? 如何在Spring的@Scheduled批注中指定特定的Scheduler

ps I am trying to schedule a method in a controller using @Scheduled annotation. ps我正在尝试使用@Scheduled注释在控制器中安排方法。

Using multiple schedulers and pointing to them via the @Scheduled annotation is unfortunately not possible . 不幸的是, 不能使用多个调度程序并通过@Scheduled注释指向它们。

However, if you really do need that flexibility, you can define the jobs in XML: 但是,如果确实需要这种灵活性,则可以用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. 这样,您可以指定需要使用的调度程序的确切ID,然后直接引用实际任务。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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