| Modifier and Type | Method and Description |
|---|---|
static <E> int |
drain(BlockingQueue<E> q,
Collection<? super E> buffer,
int numElements,
long timeout,
TimeUnit unit)
Drains the queue as
BlockingQueue.drainTo(Collection, int), but if the requested
numElements elements are not available, it will wait for them up to the specified
timeout. |
static <E> int |
drainUninterruptibly(BlockingQueue<E> q,
Collection<? super E> buffer,
int numElements,
long timeout,
TimeUnit unit)
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<E> |
newArrayBlockingQueue(int capacity)
Creates an empty
ArrayBlockingQueue instance. |
static <E> ArrayDeque<E> |
newArrayDeque()
Creates an empty
ArrayDeque instance. |
static <E> ArrayDeque<E> |
newArrayDeque(Iterable<? extends E> elements)
Creates an
ArrayDeque instance containing the given elements. |
static <E> ConcurrentLinkedQueue<E> |
newConcurrentLinkedQueue()
Creates an empty
ConcurrentLinkedQueue instance. |
static <E> ConcurrentLinkedQueue<E> |
newConcurrentLinkedQueue(Iterable<? extends E> elements)
Creates an
ConcurrentLinkedQueue instance containing the given elements. |
static <E> LinkedBlockingDeque<E> |
newLinkedBlockingDeque()
Creates an empty
LinkedBlockingDeque instance. |
static <E> LinkedBlockingDeque<E> |
newLinkedBlockingDeque(int capacity)
Creates a
LinkedBlockingDeque with the given (fixed) capacity. |
static <E> LinkedBlockingDeque<E> |
newLinkedBlockingDeque(Iterable<? extends E> elements)
Creates an
LinkedBlockingDeque instance containing the given elements. |
static <E> LinkedBlockingQueue<E> |
newLinkedBlockingQueue()
Creates an empty
LinkedBlockingQueue instance. |
static <E> LinkedBlockingQueue<E> |
newLinkedBlockingQueue(int capacity)
Creates a
LinkedBlockingQueue with the given (fixed) capacity. |
static <E> LinkedBlockingQueue<E> |
newLinkedBlockingQueue(Iterable<? extends E> elements)
Creates an
LinkedBlockingQueue instance containing the given elements. |
static <E> PriorityBlockingQueue<E> |
newPriorityBlockingQueue()
Creates an empty
PriorityBlockingQueue instance. |
static <E> PriorityBlockingQueue<E> |
newPriorityBlockingQueue(Iterable<? extends E> elements)
Creates an
PriorityBlockingQueue instance containing the given elements. |
static <E> PriorityQueue<E> |
newPriorityQueue()
Creates an empty
PriorityQueue instance. |
static <E> PriorityQueue<E> |
newPriorityQueue(Iterable<? extends E> elements)
Creates an
PriorityQueue instance containing the given elements. |
static <E> SynchronousQueue<E> |
newSynchronousQueue()
Creates an empty
SynchronousQueue instance. |
static <E> Queue<E> |
synchronizedQueue(Queue<E> queue)
Returns a synchronized (thread-safe) queue backed by the specified queue.
|
public static <E> ArrayBlockingQueue<E> newArrayBlockingQueue(int capacity)
ArrayBlockingQueue instance.ArrayBlockingQueuepublic static <E> ArrayDeque<E> newArrayDeque()
ArrayDeque instance.ArrayDequepublic static <E> ArrayDeque<E> newArrayDeque(Iterable<? extends E> elements)
ArrayDeque instance containing the given elements.elements - the elements that the queue should contain, in orderArrayDeque containing those elementspublic static <E> ConcurrentLinkedQueue<E> newConcurrentLinkedQueue()
ConcurrentLinkedQueue instance.ConcurrentLinkedQueuepublic static <E> ConcurrentLinkedQueue<E> newConcurrentLinkedQueue(Iterable<? extends E> elements)
ConcurrentLinkedQueue instance containing the given elements.elements - the elements that the queue should contain, in orderConcurrentLinkedQueue containing those elementspublic static <E> LinkedBlockingDeque<E> newLinkedBlockingDeque()
LinkedBlockingDeque instance.LinkedBlockingDequepublic static <E> LinkedBlockingDeque<E> newLinkedBlockingDeque(int capacity)
LinkedBlockingDeque with the given (fixed) capacity.capacity - the capacity of this dequeLinkedBlockingDequeIllegalArgumentException - if capacity is less than 1public static <E> LinkedBlockingDeque<E> newLinkedBlockingDeque(Iterable<? extends E> elements)
LinkedBlockingDeque instance containing the given elements.elements - the elements that the queue should contain, in orderLinkedBlockingDeque containing those elementspublic static <E> LinkedBlockingQueue<E> newLinkedBlockingQueue()
LinkedBlockingQueue instance.LinkedBlockingQueuepublic static <E> LinkedBlockingQueue<E> newLinkedBlockingQueue(int capacity)
LinkedBlockingQueue with the given (fixed) capacity.capacity - the capacity of this queueLinkedBlockingQueueIllegalArgumentException - if capacity is less than 1public static <E> LinkedBlockingQueue<E> newLinkedBlockingQueue(Iterable<? extends E> elements)
LinkedBlockingQueue instance containing the given elements.elements - the elements that the queue should contain, in orderLinkedBlockingQueue containing those elementspublic static <E> PriorityBlockingQueue<E> newPriorityBlockingQueue()
PriorityBlockingQueue instance.PriorityBlockingQueuepublic static <E> PriorityBlockingQueue<E> newPriorityBlockingQueue(Iterable<? extends E> elements)
PriorityBlockingQueue instance containing the given elements.elements - the elements that the queue should contain, in orderPriorityBlockingQueue containing those elementspublic static <E> PriorityQueue<E> newPriorityQueue()
PriorityQueue instance.PriorityQueuepublic static <E> PriorityQueue<E> newPriorityQueue(Iterable<? extends E> elements)
PriorityQueue instance containing the given elements.elements - the elements that the queue should contain, in orderPriorityQueue containing those elementspublic static <E> SynchronousQueue<E> newSynchronousQueue()
SynchronousQueue instance.SynchronousQueue@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 drainedbuffer - where to add the transferred elementsnumElements - the number of elements to be waited fortimeout - how long to wait before giving up, in units of unitunit - a TimeUnit determining how to interpret the timeout parameterInterruptedException - 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 drainedbuffer - where to add the transferred elementsnumElements - the number of elements to be waited fortimeout - how long to wait before giving up, in units of unitunit - a TimeUnit determining how to interpret the timeout parameter@Beta 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 viewCopyright © 2010-2013. All Rights Reserved.