visad.util
Class ThreadPool
- java.lang.Object
-
- visad.util.ThreadPool
-
public class ThreadPool extends java.lang.ObjectA pool of threads which can be used to execute any Runnable tasks. Internally this class uses a java.util.concurrent.ThreadPoolExecutor, but originally it did not because the original class predates java.util.concurrent. As the internals of this class have evolved, an effort has been made to preserve the original API. Note that a java.util.concurrent.ThreadPoolExecutor does not support the notion of minimum and maximum threads so minimum threads is ignored, and maximum threads is simply the size of the thread pool.
-
-
Constructor Summary
Constructors 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 threadsThreadPool(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 threadsThreadPool(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
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description intgetTaskCount()Return the number of tasks in the queue that are running.booleanisTerminated()Has the thread pool been closed?voidprintPool()Utility method to print out the tasksvoidqueue(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 submittedvoidremove(java.lang.Runnable r)Remove this task from the tread pool.voidsetThreadMaximum(int num)Set the maximum number of pooled threadsvoidstopThreads()Shut down this thread pool.booleanwaitForTasks()Wait for currently-running tasks to finish.
-
-
-
Constructor Detail
-
ThreadPool
public ThreadPool() throws java.lang.ExceptionBuild a thread pool with the default thread name prefix and the default minimum and maximum numbers of threads.- Throws:
java.lang.Exception
-
ThreadPool
public ThreadPool(java.lang.String prefix) throws java.lang.ExceptionBuild a thread pool with the specified thread name prefix, and the default minimum and maximum numbers of threads- Parameters:
prefix-- Throws:
java.lang.Exception
-
ThreadPool
public ThreadPool(int max) throws java.lang.ExceptionBuild a thread pool with the specified maximum number of threads, and the default thread name prefix and minimum number of threads- Parameters:
max-- Throws:
java.lang.Exception
-
ThreadPool
public ThreadPool(int min, int max) throws java.lang.ExceptionBuild a thread pool with the specified minimum and maximum numbers of threads, and the default thread name prefix.- Parameters:
min-max-- Throws:
java.lang.Exception
-
ThreadPool
public ThreadPool(java.lang.String prefix, int min, int max) throws java.lang.ExceptionBuild a thread pool with the specified thread name prefix and minimum and maximum numbers of threads- Parameters:
prefix-min-max-- Throws:
java.lang.Exception
-
-
Method Detail
-
getTaskCount
public int getTaskCount()
Return the number of tasks in the queue that are running. Note this number is constantly changing so check than act is not really recommended.- Returns:
- a rough number of queued and active tasks
-
remove
public void remove(java.lang.Runnable r)
Remove this task from the tread pool.- Parameters:
r- the runnable to remove from the queue
-
isTerminated
public boolean isTerminated()
Has the thread pool been closed?- Returns:
- true if the pool has been terminated.
-
printPool
public void printPool()
Utility method to print out the tasks
-
queue
public 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- Parameters:
r- the runnable that will be executed by this thread pool.
-
waitForTasks
public boolean waitForTasks()
Wait for currently-running tasks to finish. Blocks while the internal queue of tasks is completed.- Returns:
- true
-
setThreadMaximum
public void setThreadMaximum(int num) throws java.lang.ExceptionSet the maximum number of pooled threads- Parameters:
num- the number of threads- Throws:
java.lang.Exception
-
stopThreads
public void stopThreads()
Shut down this thread pool.
-
-
DMelt 3.0 © DataMelt by jWork.ORG