Announcement Announcement Module
No announcement yet.
Scheduling and concurrency Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Scheduling and concurrency

    Hi there,

    I've been searching the forum on the issues mentioned in the title but couldn't find much.

    This is the situation. I am using:

    "org.springframework.scheduling.timer.MethodInvoki ngTimerTaskFactoryBean"
    "org.springframework.scheduling.timer.ScheduledTim erTask"
    "org.springframework.scheduling.timer.TimerFactory Bean"

    to schedule a particular code to be executed on a regular basis.

    This is the configuration:

    	<bean id="timerTask"
    		<property name="targetObject" ref="esbTransferTask" />
    		<property name="targetMethod" value="execute" />
    		<property name="arguments">
    				<!-- No object / value required yet. -->
    	<bean id="scheduledTimerTask"
    		<property name="delay" value="5000" />
    		<property name="period" value="5000" />
    		<property name="timerTask" ref="timerTask" />
    	<bean id="timerFactory"
    		<property name="scheduledTimerTasks">
    				<ref bean="scheduledTimerTask" />
    		<property name="daemon" value="true" />
    My question or problem is this: say the job takes 10 seconds to finish, but each new invocation is scheduled after 5 seconds, does this mean that several threads will be running the same code concurrently (in my example "esbTransferTask.execute()")? At any given time I want only 1 thread to be active. In my example I chose 10 seconds and 5 seconds, so that could be easily fixed. But I can not predict how long it will take before the job has finished so playing with these settings is not a solution.

    Is there any problem at all actually?

    Kind regards,


  • #2
    The Timer uses a single thread for execution. So it can't happen that multiple-timer threads are executing the same method (unless the object the method belongs to is shared between different threads/timers).

    Check the docs of the Timer for more info:

    Corresponding to each Timer object is a single background thread that is used to execute all of the timer's tasks, sequentially. Timer tasks should complete quickly. If a timer task takes excessive time to complete, it "hogs" the timer's task execution thread. This can, in turn, delay the execution of subsequent tasks, which may "bunch up" and execute in rapid succession when (and if) the offending task finally completes.


    • #3
      Hi Emergency Number

      Thanks, that answers my question perfectly.