rabbit.util
Class ThreadPool

java.lang.Object
  extended byrabbit.util.ThreadPool

public class ThreadPool
extends java.lang.Object

This is a thread pool. It uses RestartableThread.


Constructor Summary
ThreadPool(RestartableThreadFactory tf, int limit)
          Create a ThreadPool.
 
Method Summary
 RestartableThreadFactory getFactory()
          Get the current factory.
 int getLimit()
          Get the current limit of concurrent threads.
 RestartableThread getThread()
          Get a Thread.
 void returnThread(RestartableThread t)
          Return a thread to the pool.
 void setFactory(RestartableThreadFactory tf)
          Set the factory to use for creating threads.
 void setLimit(int limit)
          Set the limit.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadPool

public ThreadPool(RestartableThreadFactory tf,
                  int limit)
Create a ThreadPool.

Parameters:
tf - the RestartableThreadFactory that is used as more Threads are needed.
limit - dont create more threads than this.
Method Detail

setLimit

public void setLimit(int limit)
Set the limit.

Parameters:
limit - the new limit of concurrent threads.

getLimit

public int getLimit()
Get the current limit of concurrent threads.

Returns:
the limit of threads.

getThread

public RestartableThread getThread()
Get a Thread. This will wait for a thread to be returned if the limit is currently reached.


returnThread

public void returnThread(RestartableThread t)
Return a thread to the pool. If the thread was never part of this pool it will be ignored.

Parameters:
t - the thread to return.

setFactory

public void setFactory(RestartableThreadFactory tf)
Set the factory to use for creating threads.

Parameters:
tf - the new factory.

getFactory

public RestartableThreadFactory getFactory()
Get the current factory.

Returns:
the current factory.