• 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

when will the run() method be called ?

 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when will the run() method of TimerTask be called ? only at the scheduled time ??
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ideally, the run() method should only be called at the scheduled time... However...

- The Timer class only uses one thread, so a TimerTask may be called late if another task is currently running. With enough repeating timer tasks, a backlog could even develop.

- The Timer class uses the system time to calculate the wait times, so you can get weird results if you change the system time.

Henry
[ June 30, 2006: Message edited by: Henry Wong ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The doc says "Corresponding to each Timer object is a single background thread..." so it sounds like you get a new thread each time you do new Timer(). That would be interesting to confirm.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stan James:
The doc says "Corresponding to each Timer object is a single background thread..." so it sounds like you get a new thread each time you do new Timer(). That would be interesting to confirm.



Yes, each instance of the Timer class should have its own thread. So if you have a task that is long running, (or is schedulling critical), you could consider giving it to its own timer.

Henry
[ July 01, 2006: Message edited by: Henry Wong ]
 
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic