Package ej.bon

Class 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.

    • poll() : returns null if the queue is empty, otherwise returns and removes the first element of the FIFO queue.
    • remove() : blocks the current thread until the queue becomes not empty. returns and removes the first element of the FIFO queue.
    See Also:
    EnqueuedWeakReference
    • Constructor Detail

      • ReferenceQueue

        public ReferenceQueue()
        Creates an empty Reference queue.
    • 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, returns null.
        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