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

Spec for j.util.Timer::purge and j.util.Timer::cancel could be improved

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 22
    • None
    • core-libs
    • b23

      The spec for j.u.Timer::purge asserts:

      ================
      Removes all cancelled tasks from this timer's task queue.
      Calling this method has no effect on the behavior of the timer, but eliminates the references to the cancelled tasks from the queue.

      Returns:
      the number of tasks removed from the queue
      ================

      However the OpenJDK implementation seem to be not completely matching the spec and the following example

              Timer timer = new Timer();
              timer.schedule(new TimerTask() {
                  @Override public void run() { System.out.println("timer = " + timer); }
              }, 5000);
              timer.cancel();
              System.out.println("timer.purge() = " + timer.purge());


      prints

          timer.purge() = 0

      consistently


            jlu Justin Lu
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: