org.deken.game.utils
Class ThreadPool

java.lang.Object
  extended by java.lang.ThreadGroup
      extended by org.deken.game.utils.ThreadPool
All Implemented Interfaces:
java.lang.Thread.UncaughtExceptionHandler

public class ThreadPool
extends java.lang.ThreadGroup

Title: ThreadPool

Description: Holds thread pools.

Copyright: Copyright (c) 2005

Version:
1.0
Author:
David Brackeen (Developing Games in Java)

Constructor Summary
ThreadPool(int numThreads)
          Creates a new ThreadPool.
 
Method Summary
 void close()
          Closes this ThreadPool and returns immediately.
protected  java.lang.Runnable getTask()
           
 void join()
          Closes this ThreadPool and waits for all running threads to finish.
 void runTask(java.lang.Runnable task)
          Requests a new task to run.
 
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, uncaughtException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ThreadPool

public ThreadPool(int numThreads)
Creates a new ThreadPool.

Parameters:
numThreads - The number of threads in the pool
Method Detail

runTask

public void runTask(java.lang.Runnable task)
Requests a new task to run. This method returns immediaty, and the task executes on the next available idle thread in this ThreadPool. Tasks start execution in the order they are received.

Parameters:
task - The task to run. if null, no action is taken.

close

public void close()
Closes this ThreadPool and returns immediately. All threads are stopped, and any waiting tasks are not executed. Once a ThreadPool is closed, no more tasks can be run on this ThreadPool.


join

public void join()
Closes this ThreadPool and waits for all running threads to finish. Any waiting tasks are executed.


getTask

protected java.lang.Runnable getTask()
                              throws java.lang.InterruptedException
Returns:
Runnable
Throws:
java.lang.InterruptedException