|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsimple.util.BlockingQueue
public class BlockingQueue
This provides a quick implementation for a thread safe queue. This ensures that if there are several threads enqueuing or dequeuing from this queue that no thread will dequeue a null.
This will block a thread from dequeuing when there is not items in the queue. It will also block an enqueuer if there is no space left in the queue.
When a thread is waiting and gets notified by another thread the thread that has been notified reasserts the check for the full or empty case, this means that there will be no problems if there are several enqueuing threads and several dequeuing threads.
Constructor Summary | |
---|---|
BlockingQueue()
When the size of the BlockingQueue is not specified
then the default size of 30 is set, this BlockingQueue
cannot resize so care is need when picking a size. |
|
BlockingQueue(int capacity)
If the capacity given is less than 1 then the size of the queue is increased so that it becomes 1 this means that the queue can tolerate at least one add by a thread. |
Method Summary | |
---|---|
java.lang.Object |
dequeue()
If this dequeues from a full queue it notifys any enqueuers who were waiting to add to the full queue, so that they do not block. |
void |
enqueue(java.lang.Object object)
If this enqueues to an empty queue it notifys any dequeuers that were trying to take from the empty queue. |
int |
length()
This returns the number of objects that are actually enqueued into the BlockingQueue . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BlockingQueue()
BlockingQueue
is not specified
then the default size of 30 is set, this BlockingQueue
cannot resize so care is need when picking a size.
public BlockingQueue(int capacity)
capacity
- the initial size that this queue can handleMethod Detail |
---|
public void enqueue(java.lang.Object object) throws java.lang.InterruptedException
object
- the object to enqueue into this
BlockingQueue
.
java.lang.InterruptedException
- if an interrupt is issued.public java.lang.Object dequeue() throws java.lang.InterruptedException
java.lang.InterruptedException
- is thrown if an interrupt is
issuedpublic int length()
BlockingQueue
. If the length is zero then
a dequeue method will block.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |