| Modifier and Type | Method and Description |
|---|---|
static <E> int |
drain(BlockingQueue
Drains the queue as
BlockingQueue, but if the requested
numElements elements are not available, it will wait for them up to the specified timeout.
|
static <E> int |
drainUninterruptibly(BlockingQueue
Drains the queue as
drain(BlockingQueue, Collection, int, long, TimeUnit), but with a different behavior in case it is interrupted while waiting.
|
static <E> ArrayBlockingQueue |
newArrayBlockingQueue(int capacity)
Creates an empty
ArrayBlockingQueue with the given (fixed) capacity and nonfair access policy.
|
static <E> ArrayDeque |
newArrayDeque()
Creates an empty
ArrayDeque.
|
static <E> ArrayDeque |
newArrayDeque(Iterable
Creates an
ArrayDeque containing the elements of the specified iterable, in the order they are returned by the iterable's iterator.
|
static <E> ConcurrentLinkedQueue |
newConcurrentLinkedQueue()
Creates an empty
ConcurrentLinkedQueue.
|
static <E> ConcurrentLinkedQueue |
newConcurrentLinkedQueue(Iterable
Creates a
ConcurrentLinkedQueue containing the elements of the specified iterable, in the order they are returned by the iterable's iterator.
|
static <E> LinkedBlockingDeque |
newLinkedBlockingDeque()
Creates an empty
LinkedBlockingDeque with a capacity of
Integer.
|
static <E> LinkedBlockingDeque |
newLinkedBlockingDeque(int capacity)
Creates an empty
LinkedBlockingDeque with the given (fixed) capacity.
|
static <E> LinkedBlockingDeque |
newLinkedBlockingDeque(Iterable
Creates a
LinkedBlockingDeque with a capacity of
Integer, containing the elements of the specified iterable, in the order they are returned by the iterable's iterator.
|
static <E> LinkedBlockingQueue |
newLinkedBlockingQueue()
Creates an empty
LinkedBlockingQueue with a capacity of
Integer.
|
static <E> LinkedBlockingQueue |
newLinkedBlockingQueue(int capacity)
Creates an empty
LinkedBlockingQueue with the given (fixed) capacity.
|
static <E> LinkedBlockingQueue |
newLinkedBlockingQueue(Iterable
Creates a
LinkedBlockingQueue with a capacity of
Integer, containing the elements of the specified iterable, in the order they are returned by the iterable's iterator.
|
static <E extends Comparable |
newPriorityBlockingQueue()
Creates an empty
PriorityBlockingQueue with the ordering given by its elements' natural ordering.
|
static <E extends Comparable |
newPriorityBlockingQueue(Iterable
Creates a
PriorityBlockingQueue containing the given elements.
|
static <E extends Comparable |
newPriorityQueue()
Creates an empty
PriorityQueue with the ordering given by its elements' natural ordering.
|
static <E extends Comparable |
newPriorityQueue(Iterable
Creates a
PriorityQueue containing the given elements.
|
static <E> SynchronousQueue |
newSynchronousQueue()
Creates an empty
SynchronousQueue with nonfair access policy.
|
static <E> Deque |
synchronizedDeque(Deque
Returns a synchronized (thread-safe) deque backed by the specified deque.
|
static <E> Queue |
synchronizedQueue(Queue
Returns a synchronized (thread-safe) queue backed by the specified queue.
|
public static <E> ArrayBlockingQueue<E> newArrayBlockingQueue(int capacity)
ArrayBlockingQueue with the given (fixed) capacity and nonfair access policy.
public static <E> ArrayDeque<E> newArrayDeque()
ArrayDeque.
public static <E> ArrayDeque<E> newArrayDeque(Iterable <? extends E> elements)
ArrayDeque containing the elements of the specified iterable, in the order they are returned by the iterable's iterator.
public static <E> ConcurrentLinkedQueue<E> newConcurrentLinkedQueue()
ConcurrentLinkedQueue.
public static <E> ConcurrentLinkedQueue<E> newConcurrentLinkedQueue(Iterable <? extends E> elements)
ConcurrentLinkedQueue containing the elements of the specified iterable, in the order they are returned by the iterable's iterator.
public static <E> LinkedBlockingDeque<E> newLinkedBlockingDeque()
LinkedBlockingDeque with a capacity of
Integer.MAX_VALUE .
public static <E> LinkedBlockingDeque<E> newLinkedBlockingDeque(int capacity)
LinkedBlockingDeque with the given (fixed) capacity.
IllegalArgumentException - if
capacity is less than 1
public static <E> LinkedBlockingDeque<E> newLinkedBlockingDeque(Iterable <? extends E> elements)
LinkedBlockingDeque with a capacity of
Integer.MAX_VALUE , containing the elements of the specified iterable, in the order they are returned by the iterable's iterator.
public static <E> LinkedBlockingQueue<E> newLinkedBlockingQueue()
LinkedBlockingQueue with a capacity of
Integer.MAX_VALUE .
public static <E> LinkedBlockingQueue<E> newLinkedBlockingQueue(int capacity)
LinkedBlockingQueue with the given (fixed) capacity.
IllegalArgumentException - if
capacity is less than 1
public static <E> LinkedBlockingQueue<E> newLinkedBlockingQueue(Iterable <? extends E> elements)
LinkedBlockingQueue with a capacity of
Integer.MAX_VALUE , containing the elements of the specified iterable, in the order they are returned by the iterable's iterator.
elements - the elements that the queue should contain, in order
LinkedBlockingQueue containing those elements
public static <E extends Comparable> PriorityBlockingQueue <E> newPriorityBlockingQueue()
PriorityBlockingQueue with the ordering given by its elements' natural ordering.
E be
Comparable since 15.0).
public static <E extends Comparable> PriorityBlockingQueue <E> newPriorityBlockingQueue(Iterable <? extends E> elements)
PriorityBlockingQueue containing the given elements.
Note: If the specified iterable is a
SortedSet or a
PriorityQueue, this priority queue will be ordered according to the same ordering.
E be
Comparable since 15.0).
public static <E extends Comparable> PriorityQueue <E> newPriorityQueue()
PriorityQueue with the ordering given by its elements' natural ordering.
E be
Comparable since 15.0).
public static <E extends Comparable> PriorityQueue <E> newPriorityQueue(Iterable <? extends E> elements)
PriorityQueue containing the given elements.
Note: If the specified iterable is a
SortedSet or a
PriorityQueue, this priority queue will be ordered according to the same ordering.
E be
Comparable since 15.0).
public static <E> SynchronousQueue<E> newSynchronousQueue()
SynchronousQueue with nonfair access policy.
@Beta public static <E> int drain(BlockingQueue<E> q, Collection <? super E> buffer, int numElements, long timeout, TimeUnit unit) throws InterruptedException
BlockingQueue.drainTo(Collection, int) , but if the requested
numElements elements are not available, it will wait for them up to the specified timeout.
q - the blocking queue to be drained
buffer - where to add the transferred elements
numElements - the number of elements to be waited for
timeout - how long to wait before giving up, in units of
unit
unit - a
TimeUnit determining how to interpret the timeout parameter
InterruptedException - if interrupted while waiting
@Beta public static <E> int drainUninterruptibly(BlockingQueue<E> q, Collection <? super E> buffer, int numElements, long timeout, TimeUnit unit)
InterruptedException is thrown).
q - the blocking queue to be drained
buffer - where to add the transferred elements
numElements - the number of elements to be waited for
timeout - how long to wait before giving up, in units of
unit
unit - a
TimeUnit determining how to interpret the timeout parameter
public static <E> Queue<E> synchronizedQueue(Queue <E> queue)
It is imperative that the user manually synchronize on the returned queue when accessing the queue's iterator:
Queue<E> queue = Queues.synchronizedQueue(MinMaxPriorityQueue.<E>create()); ... queue.add(element); // Needn't be in synchronized block ... synchronized (queue) { // Must synchronize on queue! Iterator<E> i = queue.iterator(); // Must be in synchronized block while (i.hasNext()) { foo(i.next()); } }
Failure to follow this advice may result in non-deterministic behavior.
The returned queue will be serializable if the specified queue is serializable.
queue - the queue to be wrapped in a synchronized view
public static <E> Deque<E> synchronizedDeque(Deque <E> deque)
It is imperative that the user manually synchronize on the returned deque when accessing any of the deque's iterators:
Deque<E> deque = Queues.synchronizedDeque(Queues.<E>newArrayDeque()); ... deque.add(element); // Needn't be in synchronized block ... synchronized (deque) { // Must synchronize on deque! Iterator<E> i = deque.iterator(); // Must be in synchronized block while (i.hasNext()) { foo(i.next()); } }
Failure to follow this advice may result in non-deterministic behavior.
The returned deque will be serializable if the specified deque is serializable.
deque - the deque to be wrapped in a synchronized view