|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttribble.util.FifoQueue
public class FifoQueue
Generic FIFO queue. Implements a first-in first-out (FIFO) circular queue, with get and put methods.
Puts (writes) and gets (reads) to the queue are synchronized, so that a producer thread can add items to the queue while another thread is simultaneously retrieving items from the queue, without contention. However, this implementation reduces the number of synchronization calls required, making it more efficient than a fully synchronized queue class.
Note that this class is designed to support a single writer thread that calls
the put()
method, and a single reader thread that calls the
get()
method. Multiple unsynchronized writers and multiple
readers are not supported by this class.
Copyright ©2007 by David R. Tribble, all rights reserved.
Permission is granted to any person or entity except those designated by
by the United States Department of State as a terrorist, or terrorist
government or agency, to use and distribute this source code provided
that the original copyright notice remains present and unaltered.
Constructor Summary | |
---|---|
FifoQueue()
Default constructor. |
|
FifoQueue(int size)
Constructor. |
Method Summary | |
---|---|
protected void |
finalize()
Finalization. |
java.lang.Object |
get()
Remove an item from the queue. |
boolean |
put(java.lang.Object item)
Insert an item into the queue. |
int |
size()
Determine the number of items in this queue. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public FifoQueue()
public FifoQueue(int size)
size
- Maximum number of items that the queue can hold at one time.
java.lang.IllegalArgumentException
- (unchecked)
Thrown if size is less than 1.Method Detail |
---|
public boolean put(java.lang.Object item)
Note that this method is not synchronized, and does not need to be as long as there is only one producer thread calling this method at any given moment.
item
- Object to add to the tail of the queue. This cannot be null.
java.lang.NullPointerException
- (unchecked)
Thrown if item is null.public java.lang.Object get()
Note that this method is not synchronized, and does not need to be as long as there is only one consumer thread calling this method at any given moment.
public int size()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |