org.apache.commons.threadpool
Class MTQueue

java.lang.Object
  extended by org.apache.commons.threadpool.MTQueue

public class MTQueue
extends Object

A multithreaded blocking queue which is very useful for implementing producer-consumer style threading patterns.

Multiple blocking threads can wait for items being added to the queue while other threads add to the queue.

Non blocking and timout based modes of access are possible as well.

Version:
$Revision: 155472 $
Author:
James Strachan

Constructor Summary
MTQueue()
           
 
Method Summary
 void add(Object object)
          adds a new object to the end of the queue.
 Object remove()
          Removes the first object from the queue, blocking until one is available.
 Object remove(long timeout)
          Removes the first object from the queue, blocking only up to the given timeout time.
 Object removeNoWait()
          Removes the first object from the queue without blocking.
 int size()
          Returns the current number of object in the queue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MTQueue

public MTQueue()
Method Detail

size

public int size()
Returns the current number of object in the queue


add

public void add(Object object)
adds a new object to the end of the queue. At least one thread will be notified.


remove

public Object remove()
Removes the first object from the queue, blocking until one is available. Note that this method will never return null and could block forever.


remove

public Object remove(long timeout)
Removes the first object from the queue, blocking only up to the given timeout time.


removeNoWait

public Object removeNoWait()
Removes the first object from the queue without blocking. This method will return immediately with an item from the queue or null.

Returns:
the first object removed from the queue or null if the queue is empty


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.