E - the type of elements held in this collectionpublic class ResizableCapacityLinkedBlockingQueue<E> extends AbstractQueue<E> implements BlockingQueue<E>, Serializable
setCapacity(int) method, allowing us to
change the capacity of the queue while it is in use.
The documentation for LinkedBlockingQueue follows...
An optionally-bounded blocking queue based on linked nodes. This queue orders elements FIFO (first-in-first-out). The head of the queue is that element that has been on the queue the longest time. The tail of the queue is that element that has been on the queue the shortest time. New elements are inserted at the tail of the queue, and the queue retrieval operations obtain elements at the head of the queue. Linked queues typically have higher throughput than array-based queues but less predictable performance in most concurrent applications.
The optional capacity bound constructor argument serves as a
way to prevent excessive queue expansion. The capacity, if unspecified,
is equal to Integer.MAX_VALUE. Linked nodes are
dynamically created upon each insertion unless this would bring the
queue above capacity.
This class implements all of the optional methods
of the Collection and Iterator interfaces.
This class is a member of the Java Collections Framework.
| 构造器和说明 |
|---|
ResizableCapacityLinkedBlockingQueue()
Creates a LinkedBlockingQueue with a capacity of
Integer.MAX_VALUE. |
ResizableCapacityLinkedBlockingQueue(Collection<? extends E> c)
Creates a LinkedBlockingQueue with a capacity of
Integer.MAX_VALUE, initially containing the elements of the
given collection,
added in traversal order of the collection's iterator. |
ResizableCapacityLinkedBlockingQueue(int capacity)
Creates a LinkedBlockingQueue with the given (fixed) capacity.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
clear() |
int |
drainTo(Collection<? super E> c) |
int |
drainTo(Collection<? super E> c,
int maxElements) |
Iterator<E> |
iterator()
Returns an iterator over the elements in this queue in proper sequence.
|
boolean |
offer(E o)
Inserts the specified element at the tail of this queue if possible,
returning immediately if this queue is full.
|
boolean |
offer(E o,
long timeout,
TimeUnit unit)
Inserts the specified element at the tail of this queue, waiting if
necessary up to the specified wait time for space to become available.
|
E |
peek() |
E |
poll() |
E |
poll(long timeout,
TimeUnit unit) |
void |
put(E o)
Adds the specified element to the tail of this queue, waiting if
necessary for space to become available.
|
int |
remainingCapacity()
Returns the number of elements that this queue can ideally (in
the absence of memory or resource constraints) accept without
blocking.
|
boolean |
remove(Object o) |
void |
setCapacity(int capacity)
Set a new capacity for the queue.
|
int |
size()
Returns the number of elements in this queue.
|
E |
take() |
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
String |
toString() |
add, addAll, element, removecontains, containsAll, isEmpty, removeAll, retainAllclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitadd, containsaddAll, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, streampublic ResizableCapacityLinkedBlockingQueue()
Integer.MAX_VALUE.public ResizableCapacityLinkedBlockingQueue(int capacity)
capacity - the capacity of this queue.IllegalArgumentException - if capacity is not greater
than zero.public ResizableCapacityLinkedBlockingQueue(Collection<? extends E> c)
Integer.MAX_VALUE, initially containing the elements of the
given collection,
added in traversal order of the collection's iterator.c - the collection of elements to initially containNullPointerException - if c or any element within it
is nullpublic int size()
size 在接口中 Collection<E>size 在类中 AbstractCollection<E>public void setCapacity(int capacity)
put(Object) invocations to succeed if the new
capacity is larger than the queue.capacity - the new capacity for the queuepublic int remainingCapacity()
Note that you cannot always tell if an attempt to add an element will succeed by inspecting remainingCapacity because it may be the case that a waiting consumer is ready to take an element out of an otherwise full queue.
remainingCapacity 在接口中 BlockingQueue<E>public void put(E o) throws InterruptedException
put 在接口中 BlockingQueue<E>o - the element to addInterruptedException - if interrupted while waiting.NullPointerException - if the specified element is null.public boolean offer(E o, long timeout, TimeUnit unit) throws InterruptedException
offer 在接口中 BlockingQueue<E>o - the element to addtimeout - how long to wait before giving up, in units of
unitunit - a TimeUnit determining how to interpret the
timeout parameterInterruptedException - if interrupted while waiting.NullPointerException - if the specified element is null.public boolean offer(E o)
offer 在接口中 BlockingQueue<E>offer 在接口中 Queue<E>o - the element to add.NullPointerException - if the specified element is nullpublic E take() throws InterruptedException
take 在接口中 BlockingQueue<E>InterruptedExceptionpublic E poll(long timeout, TimeUnit unit) throws InterruptedException
poll 在接口中 BlockingQueue<E>InterruptedExceptionpublic boolean remove(Object o)
remove 在接口中 Collection<E>remove 在接口中 BlockingQueue<E>remove 在类中 AbstractCollection<E>public Object[] toArray()
toArray 在接口中 Collection<E>toArray 在类中 AbstractCollection<E>public <T> T[] toArray(T[] a)
toArray 在接口中 Collection<E>toArray 在类中 AbstractCollection<E>public String toString()
toString 在类中 AbstractCollection<E>public void clear()
clear 在接口中 Collection<E>clear 在类中 AbstractQueue<E>public int drainTo(Collection<? super E> c)
drainTo 在接口中 BlockingQueue<E>public int drainTo(Collection<? super E> c, int maxElements)
drainTo 在接口中 BlockingQueue<E>public Iterator<E> iterator()
ConcurrentModificationException,
and guarantees to traverse elements as they existed upon
construction of the iterator, and may (but is not guaranteed to)
reflect any modifications subsequent to construction.iterator 在接口中 Iterable<E>iterator 在接口中 Collection<E>iterator 在类中 AbstractCollection<E>Copyright © 2022. All rights reserved.