qflib 0.98.0

de.qfs.lib.util
Class ThreadPool

java.lang.Object
  |
  +--de.qfs.lib.util.ThreadPool

public class ThreadPool
extends java.lang.Object

A Thread pool manages a number of Threads to execute asynchronous calls. It helps to avoid Thread creation overhead by keeping the Threads alive and waiting for something to do.

The number of live Threads can be customized with the parameters to its constructor. Threads are assigned first come first serve. The priority of of the calling Thread does not make any difference.

Calls are executed by passing a Runnable to execute. Its run Method will be called from the next available Thread.

Version:
$Revision: 1.4 $
Author:
Gregor Schmid

Constructor Summary
ThreadPool(int min, int avg, int max)
          Create a new ThreadPool.
ThreadPool(int min, int avg, int max, java.lang.ThreadGroup group)
          Create a new ThreadPool.
 
Method Summary
 void execute(java.lang.Runnable run)
          Execute a runnable in the next available Thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadPool

public ThreadPool(int min,
                  int avg,
                  int max)
Create a new ThreadPool.
Parameters:
min - Initial number of threads to create.
avg - Don't release threads unless there are more than avg Threads around.
max - Create at most that many Threads.

ThreadPool

public ThreadPool(int min,
                  int avg,
                  int max,
                  java.lang.ThreadGroup group)
Create a new ThreadPool.
Parameters:
min - Initial number of threads to create.
avg - Don't release threads unless there are more than avg Threads around.
max - Create at most that many Threads.
group - Create all threads in this ThreadGroup
Method Detail

execute

public void execute(java.lang.Runnable run)
Execute a runnable in the next available Thread. If there is no Thread currently available and the maximum number of Threads is reached, the calling Thread will be blocked, until a Thread is available.
Parameters:
run - The runnable whose run method will be called.

qflib 0.98.0