public class Disposer
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
Disposer.Record
This interface is used to hold the resource to be disposed.
|
static interface |
Disposer.Target
This is an interface which should be implemented by
the classes which use Disposer.
|
Modifier and Type | Field and Description |
---|---|
private java.util.LinkedList<Disposer.Record> |
disposalQueue |
private static Disposer |
disposerInstance |
private static int |
PHANTOM |
private java.lang.ref.ReferenceQueue |
queue |
private java.util.Hashtable |
records |
private static int |
refType |
private static int |
SOFT |
private static int |
WEAK |
Modifier | Constructor and Description |
---|---|
private |
Disposer()
Private constructor to prevent outside instantiation.
|
Modifier and Type | Method and Description |
---|---|
private void |
add(java.lang.Object target,
Disposer.Record rec)
Performs the actual registration of the target object to be disposed.
|
static void |
addRecord(java.lang.Object target,
Disposer.Record rec)
Registers the target object and the native data for later disposal when
the target is unreachable.
|
private void |
addToDisposalQueue(Disposer.Record rec) |
static void |
cleanUp()
Disposes all unreachable objects and all objects in the disposal queue.
|
static void |
disposeRecord(Disposer.Record rec)
Add the object to the disposal queue.
|
private void |
disposeUnreachables()
Polls the reference queue to see if there are any unreachable objects
to be disposed.
|
private void |
processDisposalQueue() |
private static Disposer disposerInstance
private static final int WEAK
private static final int PHANTOM
private static final int SOFT
private static int refType
private final java.lang.ref.ReferenceQueue queue
private final java.util.Hashtable records
private final java.util.LinkedList<Disposer.Record> disposalQueue
private Disposer()
public static void addRecord(java.lang.Object target, Disposer.Record rec)
target
- Object to be registeredrec
- the associated DisposerRecord objectDisposerRecord
public static void disposeRecord(Disposer.Record rec)
rec
- the DisposerRecord object to be disposedpublic static void cleanUp()
private void add(java.lang.Object target, Disposer.Record rec)
target
- Object to be registered, or if target is an instance
of DisposerTarget, its associated disposer referent
will be the Object that is registeredrec
- the associated DisposerRecord objectDisposerRecord
private void addToDisposalQueue(Disposer.Record rec)
private void disposeUnreachables()
private void processDisposalQueue()