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.
JDK 6
6 b63Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
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
startup.

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
application.

Comments
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
14-11-2005

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.
09-11-2005

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.
02-11-2005

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