File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Make sure that Timer run everyday at a Specific Time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Make sure that Timer run everyday at a Specific Time" Watch "Make sure that Timer run everyday at a Specific Time" New topic
Author

Make sure that Timer run everyday at a Specific Time

James Gordon
Ranch Hand

Joined: Aug 09, 2002
Posts: 106
Hi,
I would like to schedule a task at a particular time every day with java.util.Timer.
If I would to use the schedule(TimerTask, Date, DAY_IN_MILLIS) method, I would need to be very careful as it should be sometime in the future, else the schedule won't run at all ie: if it should run at 10:00pm everyday but the Timer start (Timer object created and schedule method called) at 11:00pm, nothing would ever happened!
Therefore, I would like to know whether there is any good solutions to this. What I can think of is to add 1 day to the Date if it is already past. The next thing I can think of is to use the schedule(TimerTask, 0, DAYS_IN_MILLIS) method and check the time manually in the run() method.
What's your opinion?

Thanks.
Peter Kristensson
Ranch Hand

Joined: Jul 02, 2001
Posts: 118
You can try the first method. I've used this previously and it works.
/Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Make sure that Timer run everyday at a Specific Time