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="com.examples.foo">
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">
</property>
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">
<list>
<ref bean="exampleTask">
</ref>
</list>
</property>
All the above entries will be part of the spring xml.More then one tasks can be added to the timerfactory
</bean></property></bean></bean>
Monday, August 4, 2008
Spring timer tasks for Threads
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment