Referencepublic abstract class Reference extends Object 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. |
Fields Summary |
---|
private T | referent | ReferenceQueue | queue | Reference | next | private transient Reference | discovered | private static Lock | lock | private static Reference | pending |
Constructors Summary |
---|
Reference(T referent)
this(referent, null);
| Reference(T referent, ReferenceQueue queue)
this.referent = referent;
this.queue = (queue == null) ? ReferenceQueue.NULL : queue;
|
Methods Summary |
---|
public void | clear()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.
this.referent = null;
| public boolean | enqueue()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.
return this.queue.enqueue(this);
| public T | get()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 .
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;
| public boolean | isEnqueued()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 .
/* 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);
}
|
|