• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

scheduled java Timer job

 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Java Timer class has "schedule" and "scheduleAtFixedRate" methods for scheduling jobs. However they both require a "start" Date and time, and a period variable. If I need to specify "every Monday night at 8:00PM", how can I do that ?

2. Following above question, suppose I specify a MOnday that is wat back, say a MOnday in year of 1950, and specify period to be 7 days, then will this timer do "make up" calls to cover all of the Mondays from 1950 to 2008 ? or will it just look for the next Monday and get started on that day and on ?

Thanks
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben,

Why do not you give a trail and check it out...
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you get an answer this? Am interested to know.
 
Neelesh A Korade
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops..i didnt see JAVA API documentation before I made my earlier reply on this. For your first question, I think you should use scheduleAtFixedRate as it stands for recurring the task at fixed rate or intervals, and, if for any reason, such as garbage collection, an execution of the task gets delayed, the subsequent ones happen at a faster rate to catch up.

On the other hand, if you used schedule, if an execution slips, the next one is still distanced from it by the fixed "period" value. So there is a good chance that over a period of time your scheudled task will slip away from Monday 8PM.

For your second question, I dont think scheduleAtFixedRate will execute the task for the period that has already lapsed. But I think schedule might trigger the task right away if the start date is in the past. Am not sure though.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic