org.edg.data.reptor.test
Class ThreadPool

java.lang.Object
  extended byorg.edg.data.reptor.test.ThreadPool
All Implemented Interfaces:
java.lang.Runnable

public class ThreadPool
extends java.lang.Object
implements java.lang.Runnable

ThreadPool implementation that runs a task list.

Version:
$Id: ThreadPool.java,v 1.4 2003/08/29 08:13:10 hst Exp $
Author:
Gavin McCance

Method Summary
 boolean addTask(java.lang.Runnable task)
          Add a Runnable task to the queue.
 long getSLEEP_INTERVAL()
          Returns the worker thread sleep interval.
 boolean isAwaitingWork()
          Whether there are any idle threads in the pool.
 int numberCurrentlyRunning()
          Return the number of currently running (non-idle) threads.
 int numberInQueue()
          Return the number of tasks in the queue.
 void run()
          Method shared by all subthreads.
 void setSLEEP_INTERVAL(long SLEEP_INTERVAL)
          Sets the worker thread sleep interval.
 void shutdown()
          Shutdown all the threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

numberCurrentlyRunning

public int numberCurrentlyRunning()
Return the number of currently running (non-idle) threads.

Returns:
The nunmber of currently active threads (i.e. those running tasks).

numberInQueue

public int numberInQueue()
Return the number of tasks in the queue.

Returns:
number of tasks in queue.

isAwaitingWork

public boolean isAwaitingWork()
Whether there are any idle threads in the pool.

Returns:
boolean. True means there are idle threads.

addTask

public boolean addTask(java.lang.Runnable task)
                throws java.lang.IllegalThreadStateException
Add a Runnable task to the queue.

Parameters:
task - The Runnable task to add.
Returns:
Flag indicating whether the task was accepted onto the queue. False means that there was not enough space in the queue, as determind by maximumTasksInQueue elememt of the ThreadPool(int, int, boolean) Constructor; in this case the task WILL NOT be run, so the calling class should always check.
Throws:
java.lang.IllegalThreadStateException - if the pool has been stopped.

shutdown

public void shutdown()
Shutdown all the threads. They will stop AFTER finshing the current tasks. The threads in the Runnable tasks are NOT notified or interrupted; they are left to finish naturally. Upon VM shutdown, the VM will wait for the threads to complete if the daemon option was set false in the ThreadPool(int,int,boolean) constructor}. If set true, the threads will be killed.


getSLEEP_INTERVAL

public long getSLEEP_INTERVAL()
Returns the worker thread sleep interval.

Returns:
in milliseconds.

setSLEEP_INTERVAL

public void setSLEEP_INTERVAL(long SLEEP_INTERVAL)
Sets the worker thread sleep interval. This is the period of time the work threads sleep for before checking the queue to see if there is more work for them.

Parameters:
SLEEP_INTERVAL - (milliseconds)

run

public void run()
Method shared by all subthreads. This will look at the queue and run any Runnable task on it. Exceptions are logged.

Specified by:
run in interface java.lang.Runnable