Package org.apache.xmlrpc.util
Class ThreadPool
- java.lang.Object
-
- org.apache.xmlrpc.util.ThreadPool
-
public class ThreadPool extends java.lang.Object
Simple thread pool. A task is executed by obtaining a thread from the pool
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ThreadPool.InterruptableTask
A task, which may be interrupted, if the pool is shutting down.private class
ThreadPool.Poolable
static interface
ThreadPool.Task
The thread pool contains instances ofThreadPool.Task
.
-
Field Summary
Fields Modifier and Type Field Description private int
maxSize
private int
num
private java.util.List
runningThreads
private java.lang.ThreadGroup
threadGroup
private java.util.List
waitingTasks
private java.util.List
waitingThreads
-
Constructor Summary
Constructors Constructor Description ThreadPool(int pMaxSize, java.lang.String pName)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
addTask(ThreadPool.Task pTask)
Deprecated.No longer in use.int
getMaxThreads()
Returns the maximum number of concurrent threads.int
getNumThreads()
Returns the number of threads, which have actually been created, as opposed to the number of currently running threads.private ThreadPool.Poolable
getPoolable(ThreadPool.Task pTask, boolean pQueue)
private void
remove(ThreadPool.Poolable pPoolable)
(package private) void
repool(ThreadPool.Poolable pPoolable)
void
shutdown()
Closes the pool.boolean
startTask(ThreadPool.Task pTask)
Starts a task immediately.
-
-
-
Method Detail
-
remove
private void remove(ThreadPool.Poolable pPoolable)
-
repool
void repool(ThreadPool.Poolable pPoolable)
-
startTask
public boolean startTask(ThreadPool.Task pTask)
Starts a task immediately.- Parameters:
pTask
- The task being started.- Returns:
- True, if the task could be started immediately. False, if
the maxmimum number of concurrent tasks was exceeded. If so, you
might consider to use the
addTask(ThreadPool.Task)
method instead.
-
getPoolable
private ThreadPool.Poolable getPoolable(ThreadPool.Task pTask, boolean pQueue)
-
addTask
public boolean addTask(ThreadPool.Task pTask)
Deprecated.No longer in use.Adds a task for immediate or deferred execution.- Parameters:
pTask
- The task being added.- Returns:
- True, if the task was started immediately. False, if the task will be executed later.
-
shutdown
public void shutdown()
Closes the pool.
-
getMaxThreads
public int getMaxThreads()
Returns the maximum number of concurrent threads.- Returns:
- Maximum number of threads.
-
getNumThreads
public int getNumThreads()
Returns the number of threads, which have actually been created, as opposed to the number of currently running threads.
-
-