run a scheduled task once a day
java
Solution
If you don't have many scheduled jobs then don't add all the Spring baggage. Keep it simple.
Date date=new Date();
Timer timer = new Timer();
timer.schedule(new TimerTask(){
public void run(){
System.out.println("Im Running..."+new Date());
}
},date, 24*60*60*1000);//24*60*60*1000 add 24 hours delay between job executions.
This will do the stuff.
-Siva
Problem
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?