de.netseeker.ejoe.concurrent
Class ThreadQueue

java.lang.Object
  extended by de.netseeker.ejoe.concurrent.ThreadQueue

public class ThreadQueue
extends java.lang.Object

Since:
0.3.0
Author:
netseeker aka Michael Manske

Constructor Summary
ThreadQueue()
          Creates a new, unlimited instance of ThreadQueue
ThreadQueue(int limit)
          Creates a new instance of ThreadQueue, which will block if the amount of queued elements reaches the given limit
 
Method Summary
 void add(java.lang.Runnable thread)
          adds a new object to the end of the queue.
 int getLimit()
           
 java.lang.Runnable remove()
          Removes the first object from the queue, blocking until one is available.
 void setLimit(int limit)
          Sets the max size of this queue, adding new elements will block when the queue size would get bigger than the limit
 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

ThreadQueue

public ThreadQueue()
Creates a new, unlimited instance of ThreadQueue


ThreadQueue

public ThreadQueue(int limit)
Creates a new instance of ThreadQueue, which will block if the amount of queued elements reaches the given limit

Parameters:
limit -
Method Detail

size

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


setLimit

public void setLimit(int limit)
Sets the max size of this queue, adding new elements will block when the queue size would get bigger than the limit

Parameters:
limit - max amount of elements this queue can contain at one time

getLimit

public int getLimit()
Returns:
the limit of this queue or -1 if no limit was set

add

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


remove

public java.lang.Runnable 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.



Copyright © 2005-2007 netseeker. All Rights Reserved.