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 with the given (fixed) capacity
and nonfair access policy. |
static <E> ArrayDeque<E> |
newArrayDeque()
Creates an empty
ArrayDeque . |
static <E> ArrayDeque<E> |
newArrayDeque(Iterable<? extends E> elements)
Creates an
ArrayDeque containing the elements of the specified iterable,
in the order they are returned by the iterable's iterator. |
static <E> ConcurrentLinkedQueue<E> |
newConcurrentLinkedQueue()
Creates an empty
ConcurrentLinkedQueue . |
static <E> ConcurrentLinkedQueue<E> |
newConcurrentLinkedQueue(Iterable<? extends E> elements)
Creates a
ConcurrentLinkedQueue containing the elements of the specified iterable,
in the order they are returned by the iterable's iterator. |
static <E> LinkedBlockingDeque<E> |
newLinkedBlockingDeque()
Creates an empty
LinkedBlockingDeque with a capacity of Integer.MAX_VALUE . |
static <E> LinkedBlockingDeque<E> |
newLinkedBlockingDeque(int capacity)
Creates an empty
LinkedBlockingDeque with the given (fixed) capacity. |
static <E> LinkedBlockingDeque<E> |
newLinkedBlockingDeque(Iterable<? extends E> elements)
Creates a
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. |
static <E> LinkedBlockingQueue<E> |
newLinkedBlockingQueue()
Creates an empty
LinkedBlockingQueue with a capacity of Integer.MAX_VALUE . |
static <E> LinkedBlockingQueue<E> |
newLinkedBlockingQueue(int capacity)
Creates an empty
LinkedBlockingQueue with the given (fixed) capacity. |
static <E> LinkedBlockingQueue<E> |
newLinkedBlockingQueue(Iterable<? extends E> elements)
Creates a
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. |
static <E extends Comparable> |
newPriorityBlockingQueue()
Creates an empty
PriorityBlockingQueue with the ordering given by its
elements' natural ordering. |
static <E extends Comparable> |
newPriorityBlockingQueue(Iterable<? extends E> elements)
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<? extends E> elements)
Creates a
PriorityQueue containing the given elements. |
static <E> SynchronousQueue<E> |
newSynchronousQueue()
Creates an empty
SynchronousQueue with nonfair access policy. |
static <E> Deque<E> |
synchronizedDeque(Deque<E> deque)
Returns a synchronized (thread-safe) deque backed by the specified deque.
|
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
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 1public 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 1public 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 orderLinkedBlockingQueue
containing those elementspublic 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 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 unit
unit
- 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 unit
unit
- 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 view@Beta 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 viewCopyright © 2010-2014. All Rights Reserved.