pastafarian
pastafarian

Reputation: 1040

Spring Task Executor Scheduled too many instances of the task

I have a simple Spring Scheduled Taks defined by the following:

<context:component-scan base-package="com/test"/>
<task:scheduled-tasks>
    <task:scheduled ref="myScheduler" method="doMyTask" fixed-rate="300000"/>
</task:scheduled-tasks>

<task:scheduler id="taskScheduler" pool-size="1"/>

<task:executor id="executorWithPoolSizeRange"
               pool-size="1"
               queue-capacity="100"/>

<bean id="cleanupClass" class="com.test.CleanupClass">
   <property name="myProperty" value="3600"/>
</bean>

I would like to run a single thread synchronously every 5 minutes. However, what I get is FIVE instances of the task running consecutively every 5 minutes. Does anyone know if there is something missing from the XML description above?

I got the behavior I wanted using the @Scheduled annotations but I would rather not use annotation for the fixed-rate as I want it to be configurable outside of the code.

Thanks.

Upvotes: 0

Views: 2396

Answers (3)

Mark
Mark

Reputation: 11

the following worked for me:

  <bean id="task" class="com.foo.MyTask">
  <task:scheduled-tasks scheduler="scheduler">
    <task:scheduled ref="task" method="run" fixed-delay="300000" />
  </task:scheduled-tasks>
  <task:scheduler id="scheduler" pool-size="10" />

Greetings, Mark

Upvotes: 1

Bobby Fisher
Bobby Fisher

Reputation: 92

Another idea is to use SPEL expression from a properties file to use it with @Sched annotation. In that way it is still configurable while using that annotation.

Upvotes: 0

Bobby Fisher
Bobby Fisher

Reputation: 92

Is this the behavior you are seeing in the STS when you deploy it to tomcat? If so, you would want to undeploy the application, redeploy it and restart the application.

Upvotes: 0

Related Questions