Package org.apache.commons.collections4.queue

# Class SynchronizedQueue<E>

java.lang.Object
org.apache.commons.collections4.collection.SynchronizedCollection<E>
org.apache.commons.collections4.queue.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 behavior for a multithreaded 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

- ## Field Summary

  ### Fields inherited from class org.apache.commons.collections4.collection.SynchronizedCollection

  `lock`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `SynchronizedQueue(Queue<E> queue)`
  Constructor that wraps (not copies).
  `protected`
  `SynchronizedQueue(Queue<E> queue, Object lock)`
  Constructor that wraps (not copies).

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected Queue<E>`
  `decorated()`
  Gets the queue being decorated.
  `E`
  `element()`
  `boolean`
  `equals(Object object)`
  `int`
  `hashCode()`
  `boolean`
  `offer(E e)`
  `E`
  `peek()`
  `E`
  `poll()`
  `E`
  `remove()`
  `static <E> SynchronizedQueue<E>`
  `synchronizedQueue(Queue<E> queue)`
  Factory method to create a synchronized queue.

  ### Methods inherited from class org.apache.commons.collections4.collection.SynchronizedCollection

  `add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, removeIf, retainAll, size, synchronizedCollection, toArray, toArray, toString`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface java.util.Collection

  `addAll, clear, contains, containsAll, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray`

  ### Methods inherited from interface java.lang.Iterable

  `forEach`

  ### Methods inherited from interface java.util.Queue

  `add`

- ## Constructor Details

  - ### 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

- ## Method Details

  - ### synchronizedQueue

    public static <E> SynchronizedQueue<E> synchronizedQueue(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:
      `NullPointerException` - if queue is null

  - ### decorated

    protected Queue<E> decorated()
    Gets the queue being decorated.
    Overrides:
      `decorated` in class `SynchronizedCollection<E>`
    Returns:
      the decorated queue

  - ### element

    public E element()
    Specified by:
      `element` in interface `Queue<E>`

  - ### equals

    public boolean equals(Object object)
    Specified by:
      `equals` in interface `Collection<E>`
    Overrides:
      `equals` in class `SynchronizedCollection<E>`

  - ### hashCode

    public int hashCode()
    Specified by:
      `hashCode` in interface `Collection<E>`
    Overrides:
      `hashCode` in class `SynchronizedCollection<E>`

  - ### offer

    public boolean offer(E e)
    Specified by:
      `offer` in interface `Queue<E>`

  - ### peek

    public E peek()
    Specified by:
      `peek` in interface `Queue<E>`

  - ### poll

    public E poll()
    Specified by:
      `poll` in interface `Queue<E>`

  - ### remove

    public E remove()
    Specified by:
      `remove` in interface `Queue<E>`