|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.progeeks.util.thread.CircularQueue
public class CircularQueue
A thread safe FIFO data structure. Internally this uses an Object array to store objects. Objects are enqueued and dequeued in round-robin fashion. Once this queue is created then there is no further allocation done. Enqueues and dequeues are very efficient since it only requires two integer modifications and an array referencing.
Field Summary | |
---|---|
protected int |
capacity
|
protected java.lang.Object[] |
data
|
static int |
DEFAULT_CAPACITY
|
protected int |
head
|
protected int |
tail
|
Constructor Summary | |
---|---|
CircularQueue()
Creates a new CircularQueue object with the DEFAULT_CAPACITY. |
|
CircularQueue(int capacity)
Creates a new CircularQueue object with the specified capacity. |
Method Summary | |
---|---|
java.lang.Object |
dequeue()
Removes an object from the front of the queue. |
void |
enqueue(java.lang.Object obj)
Adds an object to the end of the queue. |
protected int |
next(int current)
Returns the next index based on the passed index, wrapping as appropriate. |
void |
waitForEmpty()
Blocks until the queue is empty. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_CAPACITY
protected int capacity
protected int head
protected int tail
protected java.lang.Object[] data
Constructor Detail |
---|
public CircularQueue()
public CircularQueue(int capacity)
Method Detail |
---|
public void enqueue(java.lang.Object obj)
public java.lang.Object dequeue() throws java.lang.InterruptedException
java.lang.InterruptedException
public void waitForEmpty() throws java.lang.InterruptedException
java.lang.InterruptedException
protected final int next(int current)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |