2

I have the following spring mvc configuration:

<task:scheduled-tasks scheduler="defaultScheduler">
   <task:scheduled ref="myTaskWorker" method="someMethod"
     fixed-rate="500" />
</task:scheduled-tasks>

When I execute the above it is not executed in every 500ms but only executed after the finishing of the previous one.

How can i resolve this?

xyz
  • 2,160
  • 3
  • 20
  • 31
  • It is not suppose to spun a new thread when there is already a thread with same job in process? – java_dude Jun 22 '15 at 12:36
  • @java_dude Then what is the exact difference between fixed-delay and fixed-rate?And can you please help me to fix my issue (initiating a new request irrespective of previous thread is being finished after a certain period of time) – xyz Jun 22 '15 at 12:40

1 Answers1

2

The difference is about time rather than number of tasks. Fixed rate will keep track of time and spun new thread to match the fixed-time of 5 seconds. So in short, you would not have multiple threads as you are expecting.

In 15 seconds, there should be three executions. But if first task takes 10 seconds and second task takes 6 seconds then on 16th second, third task is going to start. And next task, would start on 20th second (fixed-rate), only if the third task is complete by then. Hope this makes sense.

Check out detailed answer here

Community
  • 1
  • 1
java_dude
  • 4,038
  • 9
  • 36
  • 61