Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Rescheduling a Timer Task

Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have made a custom timertask class by extending the java.util.TimerTask, and a singlton timer class by extending the java.util.Timer (as i need only one timer object).Now what i am doing is scheduling repititivly my custom timertask with the timer object using the method-- timer.schedule(repSchedularObj, delay); Now i want to give user the authority to change the delay so that he/she can reschedule it(by giving a user interface to enter a delay).

Can any one suggest how to do it ?

How to check if previously(before changing the delay) the task is running or not and if running how to get the object of the previously runnig task in order to cancel it ?
Posts: 43027
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you really need to cancel a running job? It would seem to make more sense to just schedule the next iteration after the new delay. So you could just call cancel() on the TimerTask (a reference to which you should have stored somewhere), and then schedule it anew.
There's a city wid manhunt for this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic