Package ej.bon
Class ReferenceQueue<T>
- java.lang.Object
-
- ej.bon.ReferenceQueue<T>
-
- Type Parameters:
T- the type of enqueued objects
public final class ReferenceQueue<T> extends Object
ReferenceQueue represents a queue of EnqueuedWeakReference. The system is responsible for adding such EnqueuedWeakReference into the ReferenceQueue.There are two ways to retrieve and remove an element from the queue.
- See Also:
EnqueuedWeakReference
-
-
Constructor Summary
Constructors Constructor Description ReferenceQueue()Creates an emptyReferencequeue.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EnqueuedWeakReference<T>poll()Queries the queue and returns and removes the first element of the queue.EnqueuedWeakReference<T>remove()Queries the queue, returns and removes the first element of the queue.
-
-
-
Constructor Detail
-
ReferenceQueue
public ReferenceQueue()
Creates an emptyReferencequeue.
-
-
Method Detail
-
poll
@Nullable public EnqueuedWeakReference<T> poll()
Queries the queue and returns and removes the first element of the queue. If the queue is empty, returnsnull.- Returns:
- EnqueuedWeakReference or
null
-
remove
public EnqueuedWeakReference<T> remove() throws InterruptedException
Queries the queue, returns and removes the first element of the queue. If the queue is empty, blocks the current thread until the queue gets at least one element (automatically added by the system).- Returns:
- EnqueuedWeakReference
- Throws:
InterruptedException- if the thread is interrupted
-
-