• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Re-scheduling a Task - HOW?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic