Home arrow static arrow Java Programming [Archive] - java.util.Timer keeps references to cancelled tasks
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - java.util.Timer keeps references to cancelled tasks
This topic has 1 reply on 1 page.

Posts:15
Registered: 2/12/04
java.util.Timer keeps references to cancelled tasks  
Aug 9, 2004 8:32 AM



 
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?
 

Posts:458
Registered: 7/1/03
Re: java.util.Timer keeps references to cancelled tasks  
Aug 9, 2004 9:07 AM (reply 1 of 1)



 
You could write one. Timer tasks are convience code. Not incredibly difficult to implement.
 
This topic has 1 reply on 1 page.