Jacson

de.spieleck.util
Class ThreadPool

java.lang.Object
  extended byjava.lang.ThreadGroup
      extended byde.spieleck.util.ThreadPool

public class ThreadPool
extends java.lang.ThreadGroup

Implement a thread pool for dispatching arbitrary many jobs to a fixed number of workers. The tasks must implement Runnable and are provided by a TaskSource.

Version:
0.0
Author:
fsn

Nested Class Summary
protected  class ThreadPool.WorkerThread
          Inner class to actually do something.
 
Field Summary
protected  int critical
          How many tasks are still running?
protected  java.util.Map eHandlers
          Do we have special exception handlers?
protected  int runningTasks
          How many tasks are still running?
protected  TaskSource tSource
          The actual source of work
 
Constructor Summary
ThreadPool(int size, TaskSource tSource)
          Construct a pool with a choosable number of threads.
ThreadPool(TaskSource tSource)
          Construct a pool with a default number of threads.
 
Method Summary
 void addExceptionHandler(java.lang.Class e, ExceptionHandler handler)
          Protected attach a new Exception handler.
protected  void finalize()
          Do something useful on finalization time
 int getRunningTasks()
          How many tasks are still working
protected  java.lang.Runnable getTask()
          Fetch the next assignment.
 void join()
          Wait until all jobs are done.
 void uncaughtException(java.lang.Thread t, java.lang.Throwable e)
          customizable exception handling.
 void waitDone()
          Wait until we have started doing something.
 void waitStart()
          Wait until we have started doing something.
 
Methods inherited from class java.lang.ThreadGroup
activeCount, activeGroupCount, allowThreadSuspension, checkAccess, destroy, enumerate, enumerate, enumerate, enumerate, getMaxPriority, getName, getParent, interrupt, isDaemon, isDestroyed, list, parentOf, resume, setDaemon, setMaxPriority, stop, suspend, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

runningTasks

protected int runningTasks
How many tasks are still running?


critical

protected int critical
How many tasks are still running?


eHandlers

protected java.util.Map eHandlers
Do we have special exception handlers?


tSource

protected TaskSource tSource
The actual source of work

Constructor Detail

ThreadPool

public ThreadPool(TaskSource tSource)
Construct a pool with a default number of threads.


ThreadPool

public ThreadPool(int size,
                  TaskSource tSource)
Construct a pool with a choosable number of threads.

Method Detail

getTask

protected java.lang.Runnable getTask()
Fetch the next assignment.


addExceptionHandler

public void addExceptionHandler(java.lang.Class e,
                                ExceptionHandler handler)
Protected attach a new Exception handler.


waitStart

public void waitStart()
               throws java.lang.InterruptedException
Wait until we have started doing something.

Throws:
java.lang.InterruptedException

waitDone

public void waitDone()
              throws java.lang.InterruptedException
Wait until we have started doing something.

Throws:
java.lang.InterruptedException

join

public void join()
Wait until all jobs are done. That is, we have to wait for both, that every single task is done and that there are no tasks remaining any more. But in the very beginning we assume there is something to do and wait for at least one task!


getRunningTasks

public int getRunningTasks()
How many tasks are still working


uncaughtException

public void uncaughtException(java.lang.Thread t,
                              java.lang.Throwable e)
customizable exception handling.


finalize

protected void finalize()
                 throws java.lang.Throwable
Do something useful on finalization time

Throws:
java.lang.Throwable

Spieleck

Copyleft 2002 spieleck.de.