How to use timer in Spring MVC

290 views
Skip to first unread message

Dharmesh

unread,
May 15, 2008, 7:45:31 AM5/15/08
to Spring User Group Germany
Hello,
I wanted to send email at every day in my web application which I
have made using sprimg,
I have searched in google about that, So I found spring supports
java Timers, and I have got code as follows:

applicationcontext.xml
<bean id="sendEmails" class="com.SendEmails" >
</bean>

<bean id="scheduledTask"
class="org.springframework.scheduling.timer.ScheduledTimerTask">
<property name="delay" value="10000" />
<property name="period" value="50000" />
<property name="timerTask" ref="sendEmails" />

SendEmails.java
public class SendEmails extends TimerTask{
@Override
public void run() {
//this method is not executing
}
}
But, this run() method is not calling/executing.
Is any thing other requere to do this?
Is there any alternative way to schedule task? If yes, how?

Thank You Very Much
Dharmesh Nirmal

Torsten Gräßler

unread,
May 15, 2008, 11:45:35 AM5/15/08
to Spring User Group Germany
I've been using Quartz (http://www.opensymphony.com/quartz/) for quite
a long time now.
It is easy to configure and there is a Spring integration, too
(org.springframework.scheduling.quartz).

Oliver Gierke

unread,
May 15, 2008, 2:04:29 PM5/15/08
to Spring User Group Germany
Have you forgto to declare the wrapping TimerFactoryBean? The
documentation is a little tricky regarding this, as it seems to be
complete with the TimerTask section adding the necessary Factory in
the next but one section.

So you should have someting like this:

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

Regards Ollie
Reply all
Reply to author
Forward
0 new messages