net.spy.util
Class ThreadPoolManager

java.lang.Object
  extended byjava.lang.Thread
      extended bynet.spy.SpyThread
          extended bynet.spy.util.LoopingThread
              extended bynet.spy.util.ThreadPoolManager
All Implemented Interfaces:
Runnable

public class ThreadPoolManager
extends LoopingThread

Management thread for managing a ThreadPool. This thread basically gets to hear about everything that's going on and can make the decision to spawn more threads, or kill some off if necessary.


Field Summary
 
Fields inherited from class net.spy.util.LoopingThread
DEFAULT_MS_PER_LOOP
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ThreadPoolManager(ThreadGroup tg)
          Get an instance of ThreadPoolManager.
 
Method Summary
protected  void checkTooFewThreads()
          Check to see if there are too few threads to handle the current work load.
protected  void checkTooManyThreads()
          Check to see if there are too many idle threads.
protected  ThreadPool getThreadPool()
          Get the ThreadPool we're watching.
protected  void runLoop()
          Check to see if we should start up or shut down any threads.
 void setThreadPool(ThreadPool t)
          Set the ThreadPool to watch.
 void start()
          Initialize this ThreadPoolManager.
 
Methods inherited from class net.spy.util.LoopingThread
getMsPerLoop, performDelay, requestStop, run, setMsPerLoop
 
Methods inherited from class net.spy.SpyThread
getLogger
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ThreadPoolManager

public ThreadPoolManager(ThreadGroup tg)
Get an instance of ThreadPoolManager.

Parameters:
tg - the thread group in which the pool manager will exist
Method Detail

getThreadPool

protected ThreadPool getThreadPool()
Get the ThreadPool we're watching.


setThreadPool

public final void setThreadPool(ThreadPool t)
Set the ThreadPool to watch.


start

public void start()
Initialize this ThreadPoolManager.


checkTooFewThreads

protected void checkTooFewThreads()
Check to see if there are too few threads to handle the current work load. If the number of idle threads is below the minIdleThreads from the ThreadPool, but not greater than maxTotalThreads, we can spin some more threads up.


checkTooManyThreads

protected void checkTooManyThreads()
Check to see if there are too many idle threads. If the number of idle threads is above minIdleThreads, we can request to kill some off here.

The shutdown should be slow, no more than one thread per loop.


runLoop

protected void runLoop()
Check to see if we should start up or shut down any threads.

Specified by:
runLoop in class LoopingThread