org.apache.commons.io
Class FileCleaner
java.lang.Object
|
+--org.apache.commons.io.FileCleaner
- public class FileCleaner
- extends java.lang.Object
Keeps track of files awaiting deletion, and deletes them when an associated
marker object is reclaimed by the garbage collector.
This utility creates a background thread to handle file deletion.
Each file to be deleted is registered with a handler object.
When the handler object is garbage collected, the file is deleted.
- Version:
- $Id: FileCleaner.java 289999 2005-09-18 23:12:45Z scolebourne $
- Author:
- Noel Bergman, Martin Cooper
Inner Class Summary |
private static class |
FileCleaner.Tracker
Inner class which acts as the reference for a file pending deletion. |
Field Summary |
private static java.lang.ref.ReferenceQueue |
q
Queue of Tracker instances being watched. |
private static java.lang.Thread |
reaper
The thread that will clean up registered files. |
private static java.util.Collection |
trackers
Collection of Tracker instances in existence. |
Method Summary |
(package private) static void |
()
The static initializer that starts the reaper thread. |
static int |
getTrackCount()
Retrieve the number of files currently being tracked, and therefore
awaiting deletion. |
static void |
track(java.io.File file,
java.lang.Object marker)
Track the specified file, using the provided marker, deleting the file
when the marker instance is garbage collected. |
static void |
track(java.lang.String path,
java.lang.Object marker)
Track the specified file, using the provided marker, deleting the file
when the marker instance is garbage collected. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
q
private static java.lang.ref.ReferenceQueue q
- Queue of
Tracker
instances being watched.
trackers
private static java.util.Collection trackers
- Collection of
Tracker
instances in existence.
reaper
private static java.lang.Thread reaper
- The thread that will clean up registered files.
FileCleaner
public FileCleaner()
static void ()
- The static initializer that starts the reaper thread.
track
public static void track(java.io.File file,
java.lang.Object marker)
- Track the specified file, using the provided marker, deleting the file
when the marker instance is garbage collected.
- Parameters:
file
- The file to be tracked.marker
- The marker object used to track the file.
track
public static void track(java.lang.String path,
java.lang.Object marker)
- Track the specified file, using the provided marker, deleting the file
when the marker instance is garbage collected.
- Parameters:
path
- The full path to the file to be tracked.marker
- The marker object used to track the file.
getTrackCount
public static int getTrackCount()
- Retrieve the number of files currently being tracked, and therefore
awaiting deletion.
- Returns:
- the number of files being tracked.