x10.util
Class ThreadSafeQueue

java.lang.Object
  extended byx10.util.ThreadSafeQueue

public class ThreadSafeQueue
extends java.lang.Object

ThreadSafeQueue this is an implementation of a First In First Out (FIFO) data structure. This class uses synchronization to provide thread safety for adding and removing objects to and from the queue. All of the methods in this class are synchronized, therefore temporary thread blocking might occur when calling any of these methods.


Constructor Summary
ThreadSafeQueue()
          ThreadSafeQueue constructs an empty ThreadSafeQueue
 
Method Summary
 java.lang.Object dequeue()
          dequeue removes and returns the first object in the queue without blocking.
 void dequeue(java.lang.Object toDequeue)
          dequeue removes the specified object from the queue if and only if the specified object is the first object in the queue.
 java.lang.Object dequeueNextAvailable()
          dequeueNextAvailable blocks until the next object becomes available to the queue.
 void empty()
          empty completely removes all objects that are currently in the queue.
 void enqueue(java.lang.Object element)
          enqueue adds the specified object to the end of the queue
 java.lang.Object peek()
          peek returns the next available object in the queue without physically removing the object from the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadSafeQueue

public ThreadSafeQueue()
ThreadSafeQueue constructs an empty ThreadSafeQueue

Method Detail

enqueue

public void enqueue(java.lang.Object element)
enqueue adds the specified object to the end of the queue

Parameters:
element - the object to be added to the end of the queue

dequeueNextAvailable

public java.lang.Object dequeueNextAvailable()
                                      throws java.lang.InterruptedException
dequeueNextAvailable blocks until the next object becomes available to the queue. If the queue is not empty, the first object is removed from the queue and returned without blocking.

Returns:
Object - the next available object in the queue.
Throws:
java.lang.InterruptedException - if the blocked thread is interrupted before an object becomes available.

dequeue

public java.lang.Object dequeue()
dequeue removes and returns the first object in the queue without blocking. If the queue is empty, null is returned.

Returns:
Object - the next object in the queue or null if the queue is empty.

peek

public java.lang.Object peek()
peek returns the next available object in the queue without physically removing the object from the queue.

Returns:
Object the next available object in the queue or null if the queue is empty.

dequeue

public void dequeue(java.lang.Object toDequeue)
dequeue removes the specified object from the queue if and only if the specified object is the first object in the queue.

Parameters:
toDequeue - the object to dequeue

empty

public void empty()
empty completely removes all objects that are currently in the queue.



Copyright ©2000-2005 Wade Wassenberg.
On the web: http://x10.homelinux.org.
Send bug reports to x10@wass.homelinux.net.
Last Modified June 1, 2005