org.planx.util
Class ThreadPool

java.lang.Object
  extended by org.planx.util.ThreadPool

public class ThreadPool
extends Object

Author:
Henning Niss

Constructor Summary
ThreadPool()
          Create a thread pool with the default number of worker threads (currently 100).
ThreadPool(int size)
          Create a thread pool with the specified number of worker threads.
 
Method Summary
 void addWork(Runnable work)
          Add work to the thread pool.
 boolean idle()
          Check to see if the thread pool is idle (no worker threads doing useful work).
 void stop()
          Stop the thread pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadPool

public ThreadPool()
Create a thread pool with the default number of worker threads (currently 100).


ThreadPool

public ThreadPool(int size)
Create a thread pool with the specified number of worker threads.

Parameters:
size - thread pool size
Method Detail

stop

public void stop()
Stop the thread pool.

Calling stop() waits until all worker threads are idle, then interrupts each of them (after which they should all stop because, once idle, a worker thread waits for more work), and then returns.

TODO: consider forcibly stopping the workers; consider trying to stop the workers gracefully, and if this doesn't not happen within some timeout, stop them forcibly.


addWork

public void addWork(Runnable work)
Add work to the thread pool.

Parameters:
work - work to be executed by the next available worker.

idle

public boolean idle()
Check to see if the thread pool is idle (no worker threads doing useful work).

Returns:
false if at least one worker thread is doing useful work, true otherwise.


Copyright © 2010. All Rights Reserved.