java.lang.ref
abstract public class: Reference [javadoc |
source]
java.lang.Object
java.lang.ref.Reference
Direct Known Subclasses:
LoaderReference, AATextListener, WeakClassKey, AATextListener, SoftReference, Entry, BundleReference, DocReference, Entry, PhantomReference, MarkData, OwnedWeakReference, FinalReference, WeakReference, FieldReflectorKey, Finalizer
Abstract base class for reference objects. This class defines the
operations common to all reference objects. Because reference objects are
implemented in close cooperation with the garbage collector, this class may
not be subclassed directly.
- author:
Mark - Reinhold
- since:
1.2 -
| Field Summary |
|---|
| ReferenceQueue | queue | |
| Reference | next | |
| Constructor: |
Reference(T referent) {
this(referent, null);
}
|
Reference(T referent,
ReferenceQueue queue) {
this.referent = referent;
this.queue = (queue == null) ? ReferenceQueue.NULL : queue;
}
|
| Methods from java.lang.Object: |
|---|
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from java.lang.ref.Reference Detail: |
public void clear() {
this.referent = null;
}
Clears this reference object. Invoking this method will not cause this
object to be enqueued.
This method is invoked only by Java code; when the garbage collector
clears references it does so directly, without invoking this method. |
public boolean enqueue() {
return this.queue.enqueue(this);
}
Adds this reference object to the queue with which it is registered,
if any.
This method is invoked only by Java code; when the garbage collector
enqueues references it does so directly, without invoking this method. |
public T get() {
ThreadGroup tg = Thread.currentThread().getThreadGroup();
for (ThreadGroup tgn = tg;
tgn != null;
tg = tgn, tgn = tg.getParent());
Thread handler = new ReferenceHandler(tg, "Reference Handler");
/* If there were a special system-only priority greater than
* MAX_PRIORITY, it would be used here
*/
handler.setPriority(Thread.MAX_PRIORITY);
handler.setDaemon(true);
handler.start();
return this.referent;
}
Returns this reference object's referent. If this reference object has
been cleared, either by the program or by the garbage collector, then
this method returns null. |
public boolean isEnqueued() {
/* In terms of the internal states, this predicate actually tests
whether the instance is either Pending or Enqueued */
synchronized (this) {
return (this.queue != ReferenceQueue.NULL) && (this.next != null);
}
}
Tells whether or not this reference object has been enqueued, either by
the program or by the garbage collector. If this reference object was
not registered with a queue when it was created, then this method will
always return false. |