public final class FArrayBlockingQueue<E>
extends java.util.AbstractQueue<E>
implements java.util.concurrent.BlockingQueue<E>
ArrayBlockingQueue class.
When the producer threads are blocked due to a queue full event,
then the consumer threads will not signal the producers until a
lower mark is reached again. The point is to give maximum CPU
resources to the consumer threads for a while.| Constructor and Description |
|---|
FArrayBlockingQueue(int capacity)
Creates an ArrayBlockingQueue with the given (fixed)
capacity and default access policy.
|
| Modifier and Type | Method and Description |
|---|---|
int |
blockingDrainTo(java.util.Collection<? super E> c,
int maxElements)
Same as drainTo, but blocks until at least one element is available.
|
void |
clear()
Atomically removes all of the elements from this queue.
|
boolean |
contains(java.lang.Object o) |
int |
drainTo(java.util.Collection<? super E> c) |
int |
drainTo(java.util.Collection<? super E> c,
int maxElements) |
java.util.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,
java.util.concurrent.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,
java.util.concurrent.TimeUnit unit) |
void |
put(E o)
Adds the specified element to the tail of this queue, waiting if
necessary for space to become available.
|
void |
put(java.util.List<E> objects)
Like
put(Object), but for multiple entries. |
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(java.lang.Object o)
Removes a single instance of the specified element from this
queue, if it is present.
|
int |
size() |
E |
take() |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
java.lang.String |
toString() |
containsAll, isEmpty, removeAll, retainAllpublic FArrayBlockingQueue(int capacity)
capacity - the capacity of this queuejava.lang.IllegalArgumentException - if capacity is less than 1public boolean offer(E o)
offer in interface java.util.concurrent.BlockingQueue<E>offer in interface java.util.Queue<E>o - the element to add.java.lang.NullPointerException - if the specified element is nullpublic boolean offer(E o, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
offer in interface java.util.concurrent.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 parameterjava.lang.InterruptedException - if interrupted while waiting.java.lang.NullPointerException - if the specified element is null.public E poll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
poll in interface java.util.concurrent.BlockingQueue<E>java.lang.InterruptedExceptionpublic boolean remove(java.lang.Object o)
public E take() throws java.lang.InterruptedException
take in interface java.util.concurrent.BlockingQueue<E>java.lang.InterruptedExceptionpublic void put(E o) throws java.lang.InterruptedException
put in interface java.util.concurrent.BlockingQueue<E>o - the element to addjava.lang.InterruptedException - if interrupted while waiting.java.lang.NullPointerException - if the specified element is null.public void put(java.util.List<E> objects) throws java.lang.InterruptedException
put(Object), but for multiple entries.java.lang.InterruptedExceptionpublic int size()
public 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 in interface java.util.concurrent.BlockingQueue<E>public boolean contains(java.lang.Object o)
public java.lang.Object[] toArray()
public <T> T[] toArray(T[] a)
public java.lang.String toString()
toString in class java.util.AbstractCollection<E>public void clear()
public int drainTo(java.util.Collection<? super E> c)
drainTo in interface java.util.concurrent.BlockingQueue<E>public int drainTo(java.util.Collection<? super E> c, int maxElements)
drainTo in interface java.util.concurrent.BlockingQueue<E>public int blockingDrainTo(java.util.Collection<? super E> c, int maxElements) throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic java.util.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.