Class SynchronizedQueue<E>

  • Type Parameters:
    E - the type of the elements in the collection
    All Implemented Interfaces:
    Serializable, Iterable<E>, Collection<E>, Queue<E>

    public class SynchronizedQueue<E>
    extends SynchronizedCollection<E>
    implements Queue<E>
    Decorates another Queue to synchronize its behaviour for a multi-threaded environment.

    Methods are synchronized, then forwarded to the decorated queue. Iterators must be separately synchronized around the loop.

    Since:
    4.2
    See Also:
    Serialized Form
    • Constructor Detail

      • SynchronizedQueue

        protected SynchronizedQueue​(Queue<E> queue)
        Constructor that wraps (not copies).
        Parameters:
        queue - the queue to decorate, must not be null
        Throws:
        NullPointerException - if queue is null
      • SynchronizedQueue

        protected SynchronizedQueue​(Queue<E> queue,
                                    Object lock)
        Constructor that wraps (not copies).
        Parameters:
        queue - the queue to decorate, must not be null
        lock - the lock to use, must not be null
        Throws:
        NullPointerException - if queue or lock is null