• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Make sure that Timer run everyday at a Specific Time

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try the first method. I've used this previously and it works.
/Peter
 
You showed up just in time for the waffles! And this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic