简体   繁体   English

Spring Task Scheduler多次运行单个任务

[英]Spring task scheduler runs a single task multiple times

I have a scheduler that runs every minute using Spring's task namespace. 我有一个调度程序,它使用Spring的任务名称空间每分钟运行一次。 As per the documentation it should run once using one of the threads in the cached pool with a delay of 1 minute. 根据文档,它应使用缓存池中的线程之一运行一次,延迟1分钟。 But it runs another time after a random amount of time, say 5 seconds on a different thread than the one it ran previously. 但是它在随机的时间之后运行另一次时间,例如在与之前运行的线程不同的线程上运行5秒。 Not to mention, after 1 minute it will run the one which is supposed to run. 更不用说,一分钟后它将运行应该运行的那一步。 But the 5 seconds one is not supposed to run. 但是这5秒不应该运行。 I've seen similar questions in SO but there was no reported solution. 我在SO中看到过类似的问题,但是没有报告的解决方案。 In my case it works fine in my local environment and this issue only happens on Development Environment. 就我而言,它在我的本地环境中运行良好,并且此问题仅在开发环境中发生。 Is there anything wrong with this Spring feature? Spring功能有什么问题吗?

<task:annotation-driven scheduler="myScheduler" />
<task:scheduler id="myScheduler" pool-size="10"/>
<task:scheduled-tasks scheduler="myScheduler">
    <task:scheduled ref="mySchedulerBean"
                    method="doSomething" fixed-delay="60000" />
</task:scheduled-tasks>

<bean id="mySchedulerBean" class="com.mycompany.app.tasks.SchedulerBean"/>

For those who are using older versions of spring, they need to upgrade to atleast 3.2.2. 对于那些使用旧版spring的用户,他们需要升级到至少3.2.2。 And if it still doesn't fix the problem, then the context is most likely deployed twice. 而且,如果仍然不能解决问题,则很可能会两次部署上下文。 Check the app server deployment configuration to solve the problem or in some other cases, you might be doing annotation based scheduling and also be using task xml namespace, you can use either one but not both. 检查应用程序服务器部署配置以解决该问题,或者在其他一些情况下,您可能正在基于注释的计划,并且还正在使用任务xml名称空间,则可以使用其中之一,但不能同时使用。

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

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