public class BlockingQueue<T> extends java.lang.Object implements IBlockingQueue<T>
IBlockingQueue.ClosedException| Modifier and Type | Field and Description |
|---|---|
protected boolean |
closed
The queue state.
|
protected java.util.List<T> |
elems
The element storage.
|
protected java.lang.Object |
monitor
The monitor.
|
| Constructor and Description |
|---|
BlockingQueue()
Create a blocking queue.
|
| Modifier and Type | Method and Description |
|---|---|
T |
dequeue()
Dequeue an element.
|
T |
dequeue(long timeout)
Dequeue an element.
|
void |
enqueue(T element)
Enqueue an element.
|
boolean |
isClosed()
Check if the queue is closed.
|
static void |
main(java.lang.String[] args)
Main for testing.
|
T |
peek()
Peek the topmost element without dequeuing it.
|
java.util.List |
setClosed(boolean closed)
Open/close the queue.
|
int |
size()
Return the size of the queue.
|
static void |
test1(java.lang.String[] args)
Main for testing.
|
static void |
test1b(java.lang.String[] args)
Main for testing.
|
static void |
test2(java.lang.String[] args)
Main for testing.
|
protected java.util.List<T> elems
protected volatile boolean closed
protected java.lang.Object monitor
public void enqueue(T element)
enqueue in interface IBlockingQueue<T>element - The element.public T dequeue(long timeout) throws IBlockingQueue.ClosedException, TimeoutException
dequeue in interface IBlockingQueue<T>timeout - the time to wait (in millis) or -1 for no timeout.IBlockingQueue.ClosedExceptionTimeoutExceptionpublic T peek() throws IBlockingQueue.ClosedException
peek in interface IBlockingQueue<T>IBlockingQueue.ClosedExceptionpublic T dequeue() throws IBlockingQueue.ClosedException
dequeue in interface IBlockingQueue<T>IBlockingQueue.ClosedExceptionpublic boolean isClosed()
isClosed in interface IBlockingQueue<T>public java.util.List setClosed(boolean closed)
setClosed in interface IBlockingQueue<T>closed - The closed state.public int size()
size in interface IBlockingQueue<T>public static void main(java.lang.String[] args)
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic static void test1(java.lang.String[] args)
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic static void test1b(java.lang.String[] args)
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic static void test2(java.lang.String[] args)
throws java.lang.InterruptedException
java.lang.InterruptedException