JDK-4481072 : Cancelled tasks can accumulate in a Timer
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 1.3.1,1.4.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_nt
  • CPU: generic,x86
  • Submitted: 2001-07-18
  • Updated: 2017-05-16
  • Resolved: 2003-08-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
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
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b18
2004-06-14

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