I need to autoSend reports to my clients at perticular timings like
- every day at 00:01 AM
- every Week at Sunday 00:01 AM
- on day 1 of every month
- on day 1 of every year
For every day i am doing this :
public void contextInitialized(ServletContextEvent arg0) {
System.out.println("context initiallized");
System.out.println("Starting timer");
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 1);
calendar.set(Calendar.SECOND, 0);
Date alarmTime = calendar.getTime();
_timer = new Timer();
_timer.schedule(new AlarmTask(), alarmTime);
}
Here is the class where i perform my everyday task :
public class AlarmTask extends TimerTask {
public void run() {
// Do your work here; it's 00:01 AM!
}
}
It seems to work fine BUT when i start tomcat at anytime after 00:01 AM Say at 02:30 AM the task is performed as soon as the context is loaded where i need it to be performed on next day...
Is their any problem with my code ?