Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

scheduled java Timer job

 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • 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
 
pradeep jaladi
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben,

Why do not you give a trail and check it out...
 
Neelesh A Korade
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic