net.spy.util
Class ThreadPoolManager

java.lang.Object
  extended by java.lang.Thread
      extended by net.spy.SpyThread
          extended by net.spy.util.LoopingThread
              extended by net.spy.util.ThreadPoolManager
All Implemented Interfaces:
java.lang.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.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
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(java.lang.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, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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(java.lang.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.

Overrides:
start in class java.lang.Thread

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


Copyright © 1995-2005 SPY Internetworking. All Rights Reserved.