• Post Reply Bookmark Topic Watch Topic
  • New Topic

Re-scheduling a Task - HOW?  RSS feed

 
Gautam Bhutani
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am using Timer + TimerTask for scheduling purposes. I want to schedule a task and then re-schedule it.. i.e I schedule "xyz" for March 14 4:00pm; now after 4:00pm, I want to re-schedule the same task "xyz" for March 15th 5:00pm.

The method I am using for rescheduling it is: scheduleAtFixedRate.

I can schedule the task for march 14 4:00pm. However, whenever I use "scheduleAtFixedRate" to reschedule the task, it throws an exception: Task already scheduled or cancelled. How do I get around this? How can I delete a task so that I can reschedule "xyz"?

I've been at it for the past 1 week.. just cant figure it out.. any help would be appreciated..

Thanks
Gautam
[ March 27, 2006: Message edited by: Gautam Bhutani ]
 
Jonathan Moore
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can do what you're trying to do. Each Timer has a background thread and I believe once the last scheduled task has completed the Timer finishes and is eligible for garbage collection. I think this is the same as calling start() on a thread, waiting for it to finish then trying to call start() again. Once your task has completed you would need to create a new Timer to reschedule.

Cheers
Jon
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cancel the task, if not already canceled, and then call purge() on the Timer. Obviously this disallows having the same task scheduled twice on the same Timer at the same time. You could also wrap the task in another task and add that. Or you could create a new Timer.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!