United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4481072 Cancelled tasks can accumulate in a Timer
JDK-4481072 : Cancelled tasks can accumulate in a Timer

Details
Type:
Enhancement
Submit Date:
2001-07-18
Status:
Resolved
Updated Date:
2003-08-30
Project Name:
JDK
Resolved Date:
2003-08-30
Component:
core-libs
OS:
windows_nt,generic
Sub-Component:
java.util
CPU:
x86,generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.3.1,1.4.0
Fixed Versions:
5.0 (tiger)

Related Reports

Sub Tasks

Description
In one of our applications, we create a large number of TimerTask objects to implement some "timeout" behavior in a long-running server application.  When things are working normally, we wind up cancelling these tasks before the timeout occurs.

Our application was leaking memory like crazy.  Upon inspection, we realized that when a TimerTask is cancelled, it isn't removed from the Timer heap, it's just marked for deletion.  In our app, since no tasks were actually firing before they were cancelled, the queue was never examined and the (cancelled) tasks were never cleaned up.

It looks like Timer wasn't really designed to cope with creating and then subsequently cancelling large numbers of tasks.  Perhaps a note about this implemention should be added to the javadoc so that people are aware of possible problems?  Or maybe add a purge() method that would allow all the deadwood to be cleared from the timer queue?

                                    

Comments
EVALUATION

   Something should be done about this.  At the very least, the behavior should be documented.  A purge method seems like a fine idea.  Alternatively, an automatic housecleaning facility could be integerated.

joshua.bloch@Eng 2001-07-18
                                     
2001-07-18
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
generic
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b18


                                     
2004-06-14



Hardware and Software, Engineered to Work Together