FileDocCategorySizeDatePackage
ReferenceQueue.javaAPI DocAndroid 1.5 API4571Wed May 06 22:41:04 BST 2009java.lang.ref

ReferenceQueue

public class ReferenceQueue extends Object
The {@code ReferenceQueue} is the container on which reference objects are enqueued when the garbage collector detects the reachability type specified for the referent.
since
Android 1.0

Fields Summary
private Reference
head
Constructors Summary
public ReferenceQueue()
Constructs a new instance of this class.

since
Android 1.0

        super();
    
Methods Summary
synchronized voidenqueue(java.lang.ref.Reference toQueue)
Enqueues the reference object on the receiver.

param
toQueue reference object to be enqueued.
since
Android 1.0

        if (head == null) {
            toQueue.queueNext = toQueue;
        } else {
            toQueue.queueNext = head;
        }
        head = toQueue;
        notify();
    
public synchronized java.lang.ref.Referencepoll()
Returns the next available reference from the queue, removing it in the process. Does not wait for a reference to become available.

return
the next available reference, or {@code null} if no reference is immediately available
since
Android 1.0

        if (head == null) {
            return null;
        }

        Reference<? extends T> ret;

        ret = head;

        if (head == head.queueNext) {
            head = null;
        } else {
            head = head.queueNext;
        }

        ret.queueNext = null;

        return ret;
    
public java.lang.ref.Referenceremove()
Returns the next available reference from the queue, removing it in the process. Waits indefinitely for a reference to become available.

return
the next available reference
throws
InterruptedException if the blocking call was interrupted for some reason
since
Android 1.0

        return remove(0L);
    
public synchronized java.lang.ref.Referenceremove(long timeout)
Returns the next available reference from the queue, removing it in the process. Waits for a reference to become available or the given timeout period to elapse, whichever happens first.

param
timeout maximum time (in ms) to spend waiting for a reference object to become available. A value of zero results in the method waiting indefinitely.
return
the next available reference, or {@code null} if no reference becomes available within the timeout period
throws
IllegalArgumentException if the wait period is negative.
throws
InterruptedException if the blocking call was interrupted for some reason
since
Android 1.0

        if (timeout < 0) {
            throw new IllegalArgumentException();
        }

        if (timeout == 0L) {
            while (head == null) {
                wait(0L);
            }
        } else {
            long now = System.currentTimeMillis();
            long wakeupTime = now + timeout + 1L;
            while (head == null && now < wakeupTime) {
                wait(wakeupTime - now);
                now = System.currentTimeMillis();
            }
        }

        return poll();