public class ThreadPool
extends java.lang.Object
| Constructor and Description |
|---|
ThreadPool()
Build a thread pool with the default thread name prefix and the default
minimum and maximum numbers of threads.
|
ThreadPool(int max)
Build a thread pool with the specified maximum number of threads, and the
default thread name prefix and minimum number of threads
|
ThreadPool(int min,
int max)
Build a thread pool with the specified minimum and maximum numbers of
threads, and the default thread name prefix.
|
ThreadPool(java.lang.String prefix)
Build a thread pool with the specified thread name prefix, and the default
minimum and maximum numbers of threads
|
ThreadPool(java.lang.String prefix,
int min,
int max)
Build a thread pool with the specified thread name prefix and minimum and
maximum numbers of threads
|
| Modifier and Type | Method and Description |
|---|---|
int |
getTaskCount()
Return the number of tasks in the queue that are running.
|
boolean |
isTerminated()
Has the thread pool been closed?
|
void |
printPool()
Utility method to print out the tasks
|
void |
queue(java.lang.Runnable r)
Add a task to the queue; tasks are executed as soon as a thread is
available, in the order in which they are submitted
|
void |
remove(java.lang.Runnable r)
Remove this task from the tread pool.
|
void |
setThreadMaximum(int num)
Set the maximum number of pooled threads
|
void |
stopThreads()
Shut down this thread pool.
|
boolean |
waitForTasks()
Wait for currently-running tasks to finish.
|
public ThreadPool()
throws java.lang.Exception
java.lang.Exceptionpublic ThreadPool(java.lang.String prefix)
throws java.lang.Exception
prefix - java.lang.Exceptionpublic ThreadPool(int max)
throws java.lang.Exception
max - java.lang.Exceptionpublic ThreadPool(int min,
int max)
throws java.lang.Exception
min - max - java.lang.Exceptionpublic ThreadPool(java.lang.String prefix,
int min,
int max)
throws java.lang.Exception
prefix - min - max - java.lang.Exceptionpublic int getTaskCount()
public void remove(java.lang.Runnable r)
r - the runnable to remove from the queuepublic boolean isTerminated()
public void printPool()
public void queue(java.lang.Runnable r)
r - the runnable that will be executed by this thread pool.public boolean waitForTasks()
public void setThreadMaximum(int num)
throws java.lang.Exception
num - the number of threadsjava.lang.Exceptionpublic void stopThreads()