Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6487321

(timer) Timer spec should suggest use of ScheduledThreadPoolExecutor

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 7
    • 6
    • core-libs
    • b08
    • generic
    • generic
    • Not verified

    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.

      Attachments

        Activity

          People

            martin Martin Buchholz
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: