Package com.portal.common
Class ThreadPool
java.lang.Object
java.lang.ThreadGroup
com.portal.common.ThreadPool
- All Implemented Interfaces:
Thread.UncaughtExceptionHandler
A ThreadPool is a group of threads that are generally pre-started
and are re-used when finished. It is used to overcome performence
issues with startup and shutdown of threads
- Version:
- %version: 3 % %date_modified: Tue Oct 23 15:59:35 2001 %
- Author:
- larrylf
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic int
static int
static long
-
Constructor Summary
ConstructorsConstructorDescriptionInstanciate a new ThreadPool using defaults.ThreadPool
(int minThreads, int maxThreads, long timeUnused) Instanciate a new ThreadPool with the specified minimum and maximum number of active threads. -
Method Summary
Methods inherited from class java.lang.ThreadGroup
activeCount, activeGroupCount, checkAccess, destroy, enumerate, enumerate, enumerate, enumerate, getMaxPriority, getName, getParent, interrupt, isDaemon, isDestroyed, list, parentOf, resume, setDaemon, setMaxPriority, stop, suspend, toString, uncaughtException
-
Field Details
-
DEFAULT_MIN_THREADS
public static int DEFAULT_MIN_THREADS -
DEFAULT_MAX_THREADS
public static int DEFAULT_MAX_THREADS -
DEFAULT_THREAD_TIME
public static long DEFAULT_THREAD_TIME
-
-
Constructor Details
-
ThreadPool
public ThreadPool()Instanciate a new ThreadPool using defaults. -
ThreadPool
public ThreadPool(int minThreads, int maxThreads, long timeUnused) Instanciate a new ThreadPool with the specified minimum and maximum number of active threads. The timeUnused parameter is used to terminate unused threads that may be hanging around to long.- Parameters:
minThreads
- The minimum number of threads to keep in the pool Defaults to 0. THese are started immediatly (in another thread)maxThreads
- The maximum number of threads allowed. Tho pool will be allowed to grow to this many threads, if needed. Defaults to 20.timeUnused
- The amount of time (in ms) a thread is allowed to remain unused before being terminated. If 0, then threads will never die. Defaults to 0.
-
-
Method Details
-
runThis
Run a runnable in a pool thread. If all threads are busy, and less then the maximum threads have been created, then a new thread is created, and allocated to this runnable. Otherwise, it is queued up for the next available thread. NOTE: There are no enforced gurentees that a thread will become available. Thread pool threads should only be used for tasks that run for a while then die, rather then go forever, but this cannot be enforced.- Parameters:
item
- A runnable item to run in the next thread
-
runThis
Run a runnable in a pool thread. If all threads are busy, and less then the maximum threads have been created, then a new thread is created, and allocated to this runnable. Otherwise, it is queued up for the next available thread. NOTE: There are no enforced gurentees that a thread will become available. Thread pool threads should only be used for tasks that run for a while then die, rather then go forever, but this cannot be enforced.- Parameters:
item
- A runnable item to run in the next thread
-