java.lang.ref
Class ReferenceQueue<T>

java.lang.Object
  extended by java.lang.ref.ReferenceQueue<T>

public class ReferenceQueue<T>
extends Object

This is the queue, where references can enqueue themselve on. Each reference may be registered to a queue at initialization time and will be appended to the queue, when the enqueue method is called. The enqueue method may be automatically called by the garbage collector if it detects, that the object is only reachable through the Reference objects.

See Also:
Reference.enqueue()

Constructor Summary
ReferenceQueue()
          Creates a new empty reference queue.
 
Method Summary
 Reference<? extends T> poll()
          Checks if there is a reference on the queue, returning it immediately.
 Reference<? extends T> remove()
          Removes a reference from the queue, blocking until a reference is enqueued.
 Reference<? extends T> remove(long timeout)
          Removes a reference from the queue, blocking for timeout until a reference is enqueued.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReferenceQueue

public ReferenceQueue()
Creates a new empty reference queue.

Method Detail

poll

public Reference<? extends T> poll()
Checks if there is a reference on the queue, returning it immediately. The reference will be dequeued.

Returns:
a reference on the queue, if there is one, null otherwise.

remove

public Reference<? extends T> remove(long timeout)
                              throws InterruptedException
Removes a reference from the queue, blocking for timeout until a reference is enqueued.

Parameters:
timeout - the timeout period in milliseconds, 0 means wait forever.
Returns:
the reference removed from the queue, or null if timeout period expired.
Throws:
InterruptedException - if the wait was interrupted.

remove

public Reference<? extends T> remove()
                              throws InterruptedException
Removes a reference from the queue, blocking until a reference is enqueued.

Returns:
the reference removed from the queue.
Throws:
InterruptedException - if the wait was interrupted.