java.util.Timer keeps references to cancelled tasks

Does anyone know of an efficient alternative that doesn't... ?

To my surprise, after looking at Sun's code, I discovered that after a task has been scheduled, and then its cancel() method is invoked, the reference to this task from the timer heap (queue), is not removed until the task's time has expired.

This may not be such an issue in most cases, but if tasks are scheduled for long periods of time (hours), and are normally cancelled after several seconds/minutes, as part of the application logic, then these tasks keep accumulating in the heap for hours and the memory footprint of our server grows.

If each TimerTask also kept its index in the TimerHeap, then removal of a task from the queue upon cancel could have been efficient (without significantly hurting the insert/remove operation), but this is not the case in Sun's implementation, does anyone know of an alternative that does?

[932 byte] By [ophir_b] at [2007-9-30 14:58:24]
# 1
You could write one. Timer tasks are convience code. Not incredibly difficult to implement.
Kraythe at 2007-7-5 21:30:29 > top of Java-index,Archived Forums,Java Programming...