E
- the type of elements held in this collectionpublic class ArrayBlockingQueueWithShutdown<E> extends java.util.AbstractQueue<E> implements java.util.concurrent.BlockingQueue<E>
shutdown()
and start()
methods. Will
throw InterruptedException
if Queue has been shutdown on take()
and
poll(long, TimeUnit)
.
Based on ArrayBlockingQueue of OpenJDK by Doug Lea (who released ArrayBlockingQueue as public domain).
Constructor and Description |
---|
ArrayBlockingQueueWithShutdown(int capacity) |
ArrayBlockingQueueWithShutdown(int capacity,
boolean fair) |
Modifier and Type | Method and Description |
---|---|
int |
drainTo(java.util.Collection<? super E> c) |
int |
drainTo(java.util.Collection<? super E> c,
int maxElements) |
boolean |
isShutdown()
Returns true if the queue is currently shut down.
|
java.util.Iterator<E> |
iterator() |
boolean |
offer(E e) |
boolean |
offer(E e,
long timeout,
java.util.concurrent.TimeUnit unit) |
E |
peek() |
E |
poll() |
E |
poll(long timeout,
java.util.concurrent.TimeUnit unit) |
void |
put(E e)
Inserts the specified element into this queue, waiting if necessary
for space to become available.
|
int |
remainingCapacity() |
void |
shutdown()
Shutdown the Queue.
|
int |
size() |
void |
start()
Start the queue.
|
E |
take() |
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public ArrayBlockingQueueWithShutdown(int capacity)
public ArrayBlockingQueueWithShutdown(int capacity, boolean fair)
public void shutdown()
public void start()
shutdown()
.public boolean isShutdown()
public void put(E e) throws java.lang.InterruptedException
This may throw an InterruptedException
in two cases
isShutdown()
.put
in interface java.util.concurrent.BlockingQueue<E>
e
- the element to add.java.lang.InterruptedException
- if interrupted while waiting or if the queue was shut down.public boolean offer(E e, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
offer
in interface java.util.concurrent.BlockingQueue<E>
java.lang.InterruptedException
public E take() throws java.lang.InterruptedException
take
in interface java.util.concurrent.BlockingQueue<E>
java.lang.InterruptedException
public E poll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
poll
in interface java.util.concurrent.BlockingQueue<E>
java.lang.InterruptedException
public int remainingCapacity()
remainingCapacity
in interface java.util.concurrent.BlockingQueue<E>
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 size()