JDK-4809375 : File.deleteOnExit() should be implemented with shutdown hooks
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.4.0,5.0,6
  • Priority: P5
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,linux
  • CPU: generic,x86
  • Submitted: 2003-01-28
  • Updated: 2005-12-03
  • Resolved: 2005-12-03
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 Availability Release.

To download the current JDK release, click here.
6 b63Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
File.deleteOnExit() uses the JVM entry point JVM_OnExit to register an at-exit
cleanup hook. It currently does not use the shutdown hooks mechanism introduced
in 1.3 because the API predates shutdown hooks. Unfortunately it turns out that
due to implementation details these two mechanisms are not orthogonal; in order
for the JVM at-exit hooks to be called, shutdown hooks need to be initialized.
Specifically, Terminator.setup() needs to be called during core libraries

A better solution which would reduce the amount of core libraries initialization
would be to reimplement File.deleteOnExit() to use shutdown hooks. This would
delay the first call to Terminator.setup() until actually required by the

SUGGESTED FIX Matthias submitted an updated contribution. Chris has polished off the changes and made them available here: http://sunweb.ireland/~ch122065/j2se/jsn/matthias_webrev/index.html

EVALUATION The deleteOnExit mechanism can't be implemented using the current shutdown hooks mechanism as it is today (as otherwise file deletion would execute concurrently with shutdown hooks that might access those files). However we can have a second set system-specific hooks that execute after the shutdown hooks have executed. We have community contributer with an initial implementation for this but it requires some finishing off work to complete.

SUGGESTED FIX ###@###.### has provided a second installation of changes for the re-implementation of deleteOnExit as a shutdown hook. I've merged his changes with the latest mustang to get this webrev: http://sunweb.ireland/~ab23780/4809375/webrev/index.html The general approach seems okay but it does need clean-up. He's deleted Terminator but we need this for platform specific setup. Also he's moved Shutdown.java which we can probably avoid too.

EVALUATION Should be done but cannot be finished for first tiger beta. ###@###.### 2003-11-18