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?