The whole idea of java.util.Timer is to avoid the overhead of creating a new Thread for every task. So there is only one Thread to handle all the tasks scheduled on a given Timer. That it why it must execute the tasks sequentially even if scheduled at the same time. If you want two tasks to run simulateously you will need to either spawn a separate task when the trigger happens or use two Timers.
In JDK 1.5+ there is a an even more sophisticated timer called java.util.concurrent.ScheduledThreadPoolExecutor.
See the warning under Gotchas:Threads on why a sleeping task waiting for the next timer event may never waken if somebody fiddles with the system clock setting while your thread is asleep.
![]() |
and suggestions to improve this page to Roedy Green : | ||
| Canadian Mind Products | |||
| mindprod.com IP:[65.110.21.43] | |||
| Your face IP:[38.103.63.62] | The information on this page is for non-military use only. | ||
| You are visitor number 32,055. | Military use includes use by defence contractors. | ||
| You can get a fresh copy of this page from: | or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror) | ||
| http://mindprod.com/jgloss/timer.html | J:\mindprod\jgloss\timer.html | ||