| java.lang.Object net.sourceforge.groboutils.util.thread.v1.ThreadPool
ThreadPool | public class ThreadPool (Code) | | A pool of QueueThread instances, each containing an instance of
an ObjectListener implemented class. The Class to be the listener
is passed into the constructor. Requirements for the Class are:
1. it implements QueueThread.ObjectListener, 2. it has a public
constructor without any parameters.
The pool handles menial tasks such as:
- Growing the thread pool if the number of waiting objects
is above a threshold number, up to a maximum number of
threads.
- Finding the thread with the fewest number of waiting objects.
- Optimization of determining which thread to pass events to.
The pool gets much of its functionality by sharing a single SynchQueue
between all of its threads.
author: Matt Albrecht groboclown@users.sourceforge.net since: June 4, 2000 version: $Date: 2003/02/10 22:52:49 $ |
ThreadPool | public ThreadPool(Class objectListenerClass)(Code) | | Default constructor
|
ThreadPool | public ThreadPool(Class objectListenerClass, int maxThreads)(Code) | | |
ThreadPool | public ThreadPool(Class objectListenerClass, Object initData)(Code) | | Parameters: initData - if the given objectListenerClass is an instanceof ThreadObjectListener, then the initData will be passedinto the initialize( Object ) method. |
ThreadPool | public ThreadPool(Class objectListenerClass, Object initData, int maxThreads)(Code) | | |
ThreadPool | public ThreadPool(Class objectListenerClass, Object initData, int startingThreadCount, int maxThreads)(Code) | | |
addNewThread | protected synchronized QueueThread addNewThread()(Code) | | If there are not enough threads, then add one into the
internal array, start the thread, and return the created
thread.
the new thread, or null if the pool hasexceeded its maximum thread count. |
addObject | public void addObject(Object o)(Code) | | Adds the given object into the shared queue, so that the next
available thread will process it.
|
checkThreshold | protected void checkThreshold()(Code) | | Checks if the depth on the shared queue is too deep (beyond the
threshold), and if so, creates a new thread to help deal with the
situation.
|
createObjectListenerInstance | protected IObjectListener createObjectListenerInstance()(Code) | | Create an instance of the basic object listener class, as given
in the constructor.
exception: IllegalStateException - thrown if there is an errorcreating a new instance of the class. |
getMaximumThreadCount | public int getMaximumThreadCount()(Code) | | |
getObjectDepth | public int getObjectDepth()(Code) | | |
getThreadCount | public int getThreadCount()(Code) | | |
resumeThreads | public synchronized void resumeThreads()(Code) | | Resumes all threads.
|
setDepthThreshold | public void setDepthThreshold(int threshold)(Code) | | |
setMaximumThreadCount | public void setMaximumThreadCount(int max)(Code) | | |
stopThreads | public synchronized void stopThreads()(Code) | | Stops all threads.
|
suspendThreads | public synchronized void suspendThreads()(Code) | | Suspends all threads.
|
waitForThreadsToFinish | public void waitForThreadsToFinish()(Code) | | Waits for all expecting objects in the queue to be processed,
and for each thread to finish processing an object.
|
|
|