T
- the type of elements in this queue
We assume that we have only one readerpublic class Queue<T> extends 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()
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.IllegalArgumentException
- if the specified initial capacity
is negativepublic int getSize()
public boolean isStopped()
public void notifyReader()
public T pop() throws InterruptedException
null
if the queue is
stopped (see stop()
).InterruptedException
public boolean push(T value) throws InterruptedException
blockOnFull
value
- the object to add in the queue.InterruptedException
public int size()
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 T tryPop()
null
.null
if the queue is
empty.