wood burning stoves
The moose likes Java in General and the fly likes scheduled java Timer job Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "scheduled java Timer job" Watch "scheduled java Timer job" New topic

scheduled java Timer job

ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 375
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 ?

pradeep jaladi
Ranch Hand

Joined: Nov 21, 2004
Posts: 65
Hi Ben,

Why do not you give a trail and check it out...

Neelesh A Korade

Joined: Jun 07, 2007
Posts: 26
Did you get an answer this? Am interested to know.
Neelesh A Korade

Joined: Jun 07, 2007
Posts: 26
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.
I agree. Here's the link: http://aspose.com/file-tools
subject: scheduled java Timer job
It's not a secret anymore!