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 anotherQueue
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
-
-
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
All Methods Static Methods Instance Methods Concrete Methods 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, 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, toArray
-
-
-
-
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 nulllock
- the lock to use, must not be null- Throws:
NullPointerException
- if queue or lock is null
-
-
Method Detail
-
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 classSynchronizedCollection<E>
- Returns:
- the decorated queue
-
equals
public boolean equals(Object object)
- Specified by:
equals
in interfaceCollection<E>
- Overrides:
equals
in classSynchronizedCollection<E>
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfaceCollection<E>
- Overrides:
hashCode
in classSynchronizedCollection<E>
-
-