简体   繁体   中英

Spring task scheduler runs a single task multiple times

I have a scheduler that runs every minute using Spring's task namespace. As per the documentation it should run once using one of the threads in the cached pool with a delay of 1 minute. But it runs another time after a random amount of time, say 5 seconds on a different thread than the one it ran previously. 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. I've seen similar questions in SO but there was no reported solution. 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?

<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. 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.

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