Announcement Announcement Module
Collapse
No announcement yet.
Scheduling and concurrency Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

    Code:
    	<bean id="timerTask"
    		class="org.springframework.scheduling.timer.MethodInvokingTimerTaskFactoryBean">
    		<property name="targetObject" ref="esbTransferTask" />
    		<property name="targetMethod" value="execute" />
    		<property name="arguments">
    			<list>
    				<!-- No object / value required yet. -->
    				<null></null>
    			</list>
    		</property>
    	</bean>
    
    	<bean id="scheduledTimerTask"
    		class="org.springframework.scheduling.timer.ScheduledTimerTask">
    		<property name="delay" value="5000" />
    		<property name="period" value="5000" />
    		<property name="timerTask" ref="timerTask" />
    	</bean>
    
    	<bean id="timerFactory"
    		class="org.springframework.scheduling.timer.TimerFactoryBean">
    		<property name="scheduledTimerTasks">
    			<list>
    				<ref bean="scheduledTimerTask" />
    			</list>
    		</property>
    		<property name="daemon" value="true" />
    	</bean>
    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,

    Rene'

  • #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:

    http://java.sun.com/j2se/1.4.2/docs/...til/Timer.html

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

    Comment


    • #3
      Hi Emergency Number

      Thanks, that answers my question perfectly.

      Rene'

      Comment

      Working...
      X