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