Details
Description
Many users get frustrated trying to use Timer to do things
Timer cannot do, but ScheduledThreadPoolExecutor can.
We should add a paragraph to the Timer spec explaining why STPE
is the new and improved Timer.
David Holmes' excellent blog comment is a good start
http://blogs.sun.com/dholmes/entry/inside_the_hotspot_vm_clocks
Java 5.0 introduced the java.util.concurrent package and one of the concurrency utilities therein is the ScheduledThreadPoolExecutor (STPE) which is a thread pool for repeatedly executing tasks at a given rate or delay. It is effectively a more versatile replacement for the java.util.Timer/TimerTask combination, as it allows multiple service threads, accepts various time units, and doesn't require subclassing TimerTask (just implement Runnable). Configuring STPE with one thread makes it equivalent to the basic java.util.Timer. It is generally recommended to adopt STPE to replace uses of Timer/TimerTask.
Timer cannot do, but ScheduledThreadPoolExecutor can.
We should add a paragraph to the Timer spec explaining why STPE
is the new and improved Timer.
David Holmes' excellent blog comment is a good start
http://blogs.sun.com/dholmes/entry/inside_the_hotspot_vm_clocks
Java 5.0 introduced the java.util.concurrent package and one of the concurrency utilities therein is the ScheduledThreadPoolExecutor (STPE) which is a thread pool for repeatedly executing tasks at a given rate or delay. It is effectively a more versatile replacement for the java.util.Timer/TimerTask combination, as it allows multiple service threads, accepts various time units, and doesn't require subclassing TimerTask (just implement Runnable). Configuring STPE with one thread makes it equivalent to the basic java.util.Timer. It is generally recommended to adopt STPE to replace uses of Timer/TimerTask.