games.strategy.thread
Class ThreadPool

java.lang.Object
  extended by games.strategy.thread.ThreadPool

public class ThreadPool
extends java.lang.Object

A simple thread pool.

Author:
Sean Bridges

Constructor Summary
ThreadPool(int max, java.lang.String name)
          Creates a new instance of ThreadPool max is the maximum number of threads the pool can have.
 
Method Summary
 void runTask(java.lang.Runnable task)
          Run the given task.
 void shutDown()
          Shutdown the thread pool.
 void waitForAll()
          returns when all tasks run through the runTask method have finished.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadPool

public ThreadPool(int max,
                  java.lang.String name)
Creates a new instance of ThreadPool max is the maximum number of threads the pool can have. The pool may have fewer threads at any given time.

Method Detail

runTask

public void runTask(java.lang.Runnable task)
Run the given task. This method returns immediatly If the thread pool has been shut down the task will not run.


waitForAll

public void waitForAll()
returns when all tasks run through the runTask method have finished.


shutDown

public void shutDown()
Shutdown the thread pool. Currently running tasks will finish, but new tasks will not start. All threads will shutdown after finishing any tasks they may be currently running. A call to shutDown() followed by waitForAll() will ensure that no threads are running.