jetweb is hosted by Hepforge, IPPP Durham

cedar.jetweb.util
Class ThreadPool

java.lang.Object
  extended by java.lang.Thread
      extended by cedar.jetweb.util.ThreadPool
All Implemented Interfaces:
java.lang.Runnable

public class ThreadPool
extends java.lang.Thread

Represents a group of threads of which only a set number may run at one time.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  long interval
          Interval (in ms) to wait between checks
protected  int maxThreads
          Maximum number of threads to run at once
protected  java.lang.String name
          Name of ThreadPool
protected  boolean running
           
protected  java.util.LinkedList<java.lang.Thread> runningThreads
           
protected  java.util.LinkedList<java.lang.Thread> waitingThreads
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ThreadPool()
          Create ThreadPool with default parameters
ThreadPool(java.lang.String n, int max, long inter)
          Create ThreadPool with given parameters
 
Method Summary
 void add(java.lang.Thread t)
          Add a Thread to this ThreadPool.
 void halt()
          Signal the ThreadPool to stop.
 void run()
          Start checking for threads to run
 
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, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
Name of ThreadPool


maxThreads

protected int maxThreads
Maximum number of threads to run at once


interval

protected long interval
Interval (in ms) to wait between checks


waitingThreads

protected java.util.LinkedList<java.lang.Thread> waitingThreads

runningThreads

protected java.util.LinkedList<java.lang.Thread> runningThreads

running

protected volatile boolean running
Constructor Detail

ThreadPool

public ThreadPool()
Create ThreadPool with default parameters


ThreadPool

public ThreadPool(java.lang.String n,
                  int max,
                  long inter)
Create ThreadPool with given parameters

Method Detail

add

public void add(java.lang.Thread t)
Add a Thread to this ThreadPool.


run

public void run()
Start checking for threads to run

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread


halt

public void halt()
Signal the ThreadPool to stop.