Class SynchronizedQueue<E>

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

    public class SynchronizedQueue<E>
    extends SynchronizedCollection<E>
    implements java.util.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
    • Method Detail

      • synchronizedQueue

        public static <E> SynchronizedQueue<E> synchronizedQueue​(java.util.Queue<E> queue)
        Factory method to create a synchronized queue.
        Type Parameters:
        E - the type of the elements in the queue
        Parameters:
        queue - the queue to decorate, must not be null
        Returns:
        a new synchronized Queue
        Throws:
        java.lang.NullPointerException - if queue is null
      • element

        public E element()
        Specified by:
        element in interface java.util.Queue<E>
      • equals

        public boolean equals​(java.lang.Object object)
        Specified by:
        equals in interface java.util.Collection<E>
        Overrides:
        equals in class SynchronizedCollection<E>
      • offer

        public boolean offer​(E e)
        Specified by:
        offer in interface java.util.Queue<E>
      • peek

        public E peek()
        Specified by:
        peek in interface java.util.Queue<E>
      • poll

        public E poll()
        Specified by:
        poll in interface java.util.Queue<E>
      • remove

        public E remove()
        Specified by:
        remove in interface java.util.Queue<E>