de.bea.domingo.threadpool
Class SimpleThreadPool

java.lang.Object
  extended by de.bea.domingo.threadpool.SimpleThreadPool
All Implemented Interfaces:
ThreadPool, java.lang.Runnable

public final class SimpleThreadPool
extends java.lang.Object
implements java.lang.Runnable, ThreadPool

A simple implementation of a ThreadPool which is constructed with a given number of threads.

Author:
Kurt Riede

Field Summary
static int DEFAULT_NUM_THREAD
          Default number of threads in the thread pool.
static int MAX_WAIT_FOR_STOP
          Maximum amount of time to wait for a thread to stop.
static int MAX_WAIT_FOR_TASK
          Maximum amount of time to wait for a task from the queue in milli seconds.
 
Constructor Summary
SimpleThreadPool()
          Constructor.
SimpleThreadPool(DNotesMonitor monitor)
          Constructor.
SimpleThreadPool(DNotesMonitor monitor, int numberOfThreads)
          Constructor.
SimpleThreadPool(DNotesMonitor monitor, int numberOfThreads, int threadPriority)
          Constructor.
SimpleThreadPool(DNotesMonitor monitor, ThreadFactory threadFactory, int numberOfThreads)
          Constructor.
SimpleThreadPool(DNotesMonitor theMonitor, ThreadFactory theThreadFactory, int theNumberOfThreads, int theThreadPriority)
          Constructor.
SimpleThreadPool(int numberOfThreads)
          Constructor.
SimpleThreadPool(int numberOfThreads, int threadPriority)
          Constructor.
 
Method Summary
 int getRunnableCount()
          Returns number of runnable objects in the queue.
 void invokeLater(java.lang.Runnable task)
          Dispatch a new task onto this pool to be invoked asynchronously later.
 void resize(int newSize)
          Resize the thread pool.
 void run()
          The method ran by the pool of background threads.
 void stop()
          Stops the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_WAIT_FOR_TASK

public static final int MAX_WAIT_FOR_TASK
Maximum amount of time to wait for a task from the queue in milli seconds.

See Also:
Constant Field Values

MAX_WAIT_FOR_STOP

public static final int MAX_WAIT_FOR_STOP
Maximum amount of time to wait for a thread to stop.

See Also:
Constant Field Values

DEFAULT_NUM_THREAD

public static final int DEFAULT_NUM_THREAD
Default number of threads in the thread pool.

See Also:
Constant Field Values
Constructor Detail

SimpleThreadPool

public SimpleThreadPool()
                 throws ThreadPoolException
Constructor.

Throws:
ThreadPoolException - if any error occurs during starting threads

SimpleThreadPool

public SimpleThreadPool(DNotesMonitor monitor)
                 throws ThreadPoolException
Constructor.

Parameters:
monitor - the monitor
Throws:
ThreadPoolException - if any error occurs during starting threads

SimpleThreadPool

public SimpleThreadPool(int numberOfThreads)
                 throws ThreadPoolException
Constructor.

Parameters:
numberOfThreads - number of threads in pool
Throws:
ThreadPoolException - if any error occurs during starting threads

SimpleThreadPool

public SimpleThreadPool(DNotesMonitor monitor,
                        int numberOfThreads)
                 throws ThreadPoolException
Constructor.

Parameters:
monitor - ThreadPool Monitor
numberOfThreads - number of threads in pool
Throws:
ThreadPoolException - if any error occurs during starting threads
ThreadPoolException - if any error occurs during starting threads

SimpleThreadPool

public SimpleThreadPool(int numberOfThreads,
                        int threadPriority)
                 throws ThreadPoolException
Constructor.

Parameters:
numberOfThreads - number of threads in pool
threadPriority - priority of threads in pool
Throws:
ThreadPoolException - if any error occurs during starting threads

SimpleThreadPool

public SimpleThreadPool(DNotesMonitor monitor,
                        int numberOfThreads,
                        int threadPriority)
                 throws ThreadPoolException
Constructor.

Parameters:
monitor - ThreadPool Monitor
numberOfThreads - number of threads in pool
threadPriority - priority of threads in pool
Throws:
ThreadPoolException - if any error occurs during starting threads

SimpleThreadPool

public SimpleThreadPool(DNotesMonitor monitor,
                        ThreadFactory threadFactory,
                        int numberOfThreads)
                 throws ThreadPoolException
Constructor.

Parameters:
monitor - ThreadPool Monitor
threadFactory - ThreadFactory to us to create the new Threads
numberOfThreads - number of threads in pool
Throws:
ThreadPoolException - if any error occurs during starting threads

SimpleThreadPool

public SimpleThreadPool(DNotesMonitor theMonitor,
                        ThreadFactory theThreadFactory,
                        int theNumberOfThreads,
                        int theThreadPriority)
                 throws ThreadPoolException
Constructor.

Parameters:
theMonitor - ThreadPool monitor
theThreadFactory - ThreadFactory to us to create the new Threads
theNumberOfThreads - number of threads in pool
theThreadPriority - priority of threads in pool
Throws:
ThreadPoolException - if any error occurs during starting threads
Method Detail

getRunnableCount

public int getRunnableCount()
Returns number of runnable objects in the queue.

Returns:
number of objects in the queue

invokeLater

public void invokeLater(java.lang.Runnable task)
Dispatch a new task onto this pool to be invoked asynchronously later.

Specified by:
invokeLater in interface ThreadPool
Parameters:
task - the task to execute

stop

public void stop()
Description copied from interface: ThreadPool
Stops the pool.

Specified by:
stop in interface ThreadPool
See Also:
ThreadPool.stop()

resize

public void resize(int newSize)
            throws ThreadPoolException
Resize the thread pool.

Specified by:
resize in interface ThreadPool
Parameters:
newSize - new number of threads in the thread pool
Throws:
ThreadPoolException - if any error occurs during starting threads
See Also:
ThreadPool.resize(int)

run

public void run()
The method ran by the pool of background threads.

Specified by:
run in interface java.lang.Runnable


Domingo Java-API