Monday, August 4, 2008

Spring timer tasks for Threads

Create the bean which should be called on regular intervals.

This bean should extend the TimerTask and should have the run method which will be called on timely basis.

<bean id="example" class="">

Make the bean a task and provide the time interval when it needs to be called. The time could be picked from property files.

<bean id="exampleTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
<property name="period" value="${exampleTime}">
<property name="timerTask" ref="example">

Add the tasks as part of Timerfactory which will be called based on the time given.

<bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">
<property name="scheduledTimerTasks">
<ref bean="exampleTask">

All the above entries will be part of the spring xml.More then one tasks can be added to the timerfactory

No comments:

Free Domain Names @!