T
- the type of elements in this queue
We assume that we have only one readerpublic class Queue<T>
extends java.lang.Object
Constructor and Description |
---|
Queue()
Constructs an empty queue with the specified initial capacity.
|
Queue(int initialCapacity,
boolean blockOnFull)
Constructs an empty queue with the specified initial capacity.
|
Modifier and Type | Method and Description |
---|---|
int |
getSize()
Returns the numbers of elements in this queue.
|
boolean |
isStopped()
Returns true if this queue is stopped.
|
void |
notifyReader() |
T |
pop()
Takes an object in the queue and returns it.
|
boolean |
push(T value)
Adds an object in the queue.
|
int |
size()
Returns the size of this queue.
|
void |
stop()
Stop the queue.
|
T |
tryPop()
Non-blocking pop.
|
public Queue()
java.lang.IllegalArgumentException
- if the specified initial capacity
is negativepublic Queue(int initialCapacity, boolean blockOnFull)
initialCapacity
- the initial capacity of the listblockOnFull
- If it is true, block the push(Object)
is the queue is full.java.lang.IllegalArgumentException
- if the specified initial capacity
is negativepublic int getSize()
public T pop() throws java.lang.InterruptedException
null
if the queue is
stopped (see stop()
).java.lang.InterruptedException
public T tryPop()
null
.null
if the queue is
empty.public boolean push(T value) throws java.lang.InterruptedException
blockOnFull
value
- the object to add in the queue.java.lang.InterruptedException
public void stop()
Reader threads (threads blocked in the pop()
method) are
notified and the pop methods return null
. Writer threads
(threads blocked in the push(Object)
method) are notified and
the added object is ignored.
Once the queue has been stopped, subsequent calls to pop()
returns null
, and subsequent calls to push(Object)
are ignored.
public boolean isStopped()
public int size()
public void notifyReader()