FileDocCategorySizeDatePackage
DeleteOnExitHook.javaAPI DocJava SE 6 API1332Tue Jun 10 00:25:32 BST 2008java.io

DeleteOnExitHook

public class DeleteOnExitHook extends Object
This class holds a set of filenames to be deleted on VM exit through a shutdown hook. A set is used both to prevent double-insertion of the same file as well as offer quick removal.

Fields Summary
private static DeleteOnExitHook
instance
private static LinkedHashSet
files
Constructors Summary
private DeleteOnExitHook()

Methods Summary
static voidadd(java.lang.String file)

	synchronized(files) {
	    if(files == null)
		throw new IllegalStateException("Shutdown in progress");

	    files.add(file);
	}
    
static java.io.DeleteOnExitHookhook()


       
	if (instance == null)
	    instance = new DeleteOnExitHook();

	return instance;
    
voidrun()

	LinkedHashSet<String> theFiles;

	synchronized (files) {
	    theFiles = files;
	    files = null;
	}

	ArrayList<String> toBeDeleted = new ArrayList<String>(theFiles);

	// reverse the list to maintain previous jdk deletion order.
	// Last in first deleted.
	Collections.reverse(toBeDeleted);
	for (String filename : toBeDeleted) {
	    (new File(filename)).delete();
	}