com.quadrique.jbuildingblocks.core.thread
Class JbbThreadPool
java.lang.Object
java.lang.ThreadGroup
com.quadrique.jbuildingblocks.core.thread.JbbThreadPool
- All Implemented Interfaces:
- Thread.UncaughtExceptionHandler
public class JbbThreadPool
- extends ThreadGroup
This class implements a thread pool. Thread pools are mainly used for
thread intensive application. The main advantages of a thread pool is
that you don't incur the cost of continuously creating/deleting threads
and that you limit the number of possible threads.
Typical usage:
ThreadPool lPool = new ThreadPool();
lPool.execute( new Runnable()
{
public void run()
{
// execute this function on an existing
// thread from the pool.
...
}
}
);
The threads in the pool execute any given Runnable
instance on a FIFO basis.
The pool has an initial number of threads that are created
upon startup. Based on the load, the number of threads either
stays the same or is increased until the maximum number of
threads is reached (in which case, the Runnable instances will
be queued and executed as soon as the threads are released)
The thread pool creates the threads in their own thread group.
| 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, uncaughtException |
MAX_NB_OF_THREADS
public static final int MAX_NB_OF_THREADS
- constants
- See Also:
- Constant Field Values
newInstance
public static JbbThreadPool newInstance(String zName,
int zInitialNbOfThreads,
int zMaxNbOfThreads)
throws Exception
- Throws:
Exception
execute
public final void execute(Runnable zTarget)
- The run() method of the given Runnable object will be executed
by one of the threads of the pool.
Please note that if the thread pool is shutting down, this method
returns immediately without executing the target.
- Parameters:
zTarget - the runnable instance to execute
- Throws:
JbbShuttingDownException - if you try to execute a method while
the thread pool is shutting down
shutdown
public final void shutdown(long zMaxMilliSeconds)
- Stops the execution of the thread pool including its
associated threads (if a thread is currently executing
a Runnable instance, it will stop as soon as the run()
method returns).
If there is still some Runnable instances in the internal
queue, they will be discarded
- Parameters:
zMaxMilliSeconds - the maximum amount of time to
wait for all the threads to be stopped
getCurrentNbOfThreadsInPool
public final int getCurrentNbOfThreadsInPool()
- Returns:
- the current number of threads in the pool
getMaxNbOfThreadsReachedInPool
public final int getMaxNbOfThreadsReachedInPool()
- Returns:
- the current number of threads in the pool
Copyright © 2001-2008 Quadrique Corporation. All Rights Reserved.