My requirement is I want to schedule a task that should run once a day.For that I am using following code:
public class setAutoReminder {
EscalationDAO escalationDAO=new EscalationDAO();
final SendMail sendMail=new SendMail();
public void fetch(){
Date date=new Date();
Timer timer = new Timer();
timer.schedule(new TimerTask(){
public void run(){
int number=escalationDAO.getAutoReminder();
System.out.println(number);
if(number>0) {
sendMail.sendMail();
}
}
},date, 1000000000);
}
}
but this code runs multiple times.I want it to runs once a day.What should I do?
If you don’t have many scheduled jobs then don’t add all the Spring baggage.
Keep it simple.
This will do the stuff.
-Siva