FileDocCategorySizeDatePackage
Reference.javaAPI DocJava SE 5 API6948Fri Aug 26 14:57:06 BST 2005java.lang.ref

Reference

public 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.
version
1.41, 04/20/04
author
Mark Reinhold
since
1.2

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 voidclear()
Clears this reference object. Invoking this method will not cause this object to be enqueued.

	this.referent = null;
    
public booleanenqueue()
Adds this reference object to the queue with which it is registered, if any.

return
true if this reference object was successfully enqueued; false if it was already enqueued or if it was not registered with a queue when it was created

	return this.queue.enqueue(this);
    
public Tget()
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.

return
The object to which this reference refers, or null if this reference object has been cleared

	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 booleanisEnqueued()
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.

return
true if and only if this reference object has been enqueued

	/* 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);
	}