T
- the type of elements@ThreadSafe public final class ClosableBlockingQueue<T> extends Object implements AutoCloseable
Constructor and Description |
---|
ClosableBlockingQueue()
Creates a closable blocking queue.
|
ClosableBlockingQueue(int numElements)
Creates a closable blocking queue.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Mark the input end of this queue as closed.
|
T |
peek()
Retrieves, but does not removes, the head of this queue, waiting if necessary.
|
void |
put(T element)
Adds an element.
|
T |
take()
Retrieves and removes the head of this queue, waiting if necessary.
|
public ClosableBlockingQueue()
public ClosableBlockingQueue(int numElements)
numElements
- the lower bound on initial capacity of the queuepublic void put(T element)
element
- the element to addIllegalStateException
- if the input end of this queue has been closedpublic void close()
close
in interface AutoCloseable
@Nullable public T take() throws InterruptedException
null
if no elements are there and this queue has been closedInterruptedException
- when interrupted while waiting@Nullable public T peek() throws InterruptedException
null
if no elements are there and this queue has been closedInterruptedException
- when interrupted while waitingCopyright © 2018. All rights reserved.