com.ls.util.threading
Class StaticThreadPool

java.lang.Object
  |
  +--java.lang.ThreadGroup
        |
        +--com.ls.util.threading.ThreadPool
              |
              +--com.ls.util.threading.StaticThreadPool

public class StaticThreadPool
extends ThreadPool

This class implements a static thread pool. "Static" means that there will be always a fixed amount of threads in the pool. If load increases and more tasks should be executed in parallel than threads are available this implementation does NOT increase the number of pooled threads. It keeps the amount always at a fixed rate.

Instances of this class can be obtained either directly or through the factory method ThreadPool.newInstance(java.util.Properties). In the latter case a properties object has to be provided with the following properties:

threadPool = com.ls.util.threading.StaticThreadPool threadPool.name = [name of the thread pool] threadPool.count = [number of threads maintained by the pool]

Version:
$Revision: 1.5 $
Author:
Last modified by $Author: MFehrenbach $

Constructor Summary
StaticThreadPool(String name, int threadCount)
          Constructs a new static thread pool.
 
Method Summary
 void runTask(Runnable task)
          Executes the given task by a pool thread.
protected  void threadReady(ThreadPoolWorker worker)
          Overwritten for updating the list of idle threads.
 void waitForIdlePool()
          Waits until all threads are ready for task execution, or in other words: waits until all currently processed tasks are finished.
 void waitForIdleThread()
          Waites until a thread in the pool becomes ready for task execution.
 
Methods inherited from class com.ls.util.threading.ThreadPool
join, newInstance, setLogger, startNewWorker, startNewWorker, threadBusy, threadInitialize, threadShutdown, threadTaskCompleted, threadTaskFailed, uncaughtException
 
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, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StaticThreadPool

public StaticThreadPool(String name,
                        int threadCount)
Constructs a new static thread pool.
Parameters:
name - The name of this thread pool. This name will be reflected by the names of the worker threads.
threadCount - The amount of worker threads, that will be maintained by this thread pool.
Method Detail

waitForIdleThread

public void waitForIdleThread()
                       throws InterruptedException
Description copied from class: ThreadPool
Waites until a thread in the pool becomes ready for task execution.

Overrides:
waitForIdleThread in class ThreadPool
See Also:
ThreadPool.waitForIdleThread()

waitForIdlePool

public void waitForIdlePool()
                     throws InterruptedException
Description copied from class: ThreadPool
Waits until all threads are ready for task execution, or in other words: waits until all currently processed tasks are finished.

Overrides:
waitForIdlePool in class ThreadPool
See Also:
ThreadPool.waitForIdlePool()

runTask

public void runTask(Runnable task)
             throws InterruptedException
Description copied from class: ThreadPool
Executes the given task by a pool thread. If no pool thread is available this method blocks until one becomes available.

Overrides:
runTask in class ThreadPool
See Also:
ThreadPool.runTask(Runnable)

threadReady

protected void threadReady(ThreadPoolWorker worker)
Overwritten for updating the list of idle threads. Every worker thread that calls this method will be added to the list of idle threads.
Overrides:
threadReady in class ThreadPool
Parameters:
worker - The worker thread that will be added to the list of idle threads.
See Also:
ThreadPool.threadReady(ThreadPoolWorker)