|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.knime.core.util.ThreadPool
public class ThreadPool
Implements a sophisticated thread pool.
| Constructor Summary | |
|---|---|
|
ThreadPool(int maxThreads)
Creates a new ThreadPool with a maximum number of threads. |
protected |
ThreadPool(int maxThreads,
ThreadPool parent)
Creates a new sub pool. |
| Method Summary | ||
|---|---|---|
ThreadPool |
createSubPool()
Creates a sub pool that shares the threads with this (parent) pool. |
|
ThreadPool |
createSubPool(int maxThreads)
Creates a sub pool that shares the threads with this (parent) pool. |
|
static ThreadPool |
currentPool()
If the current thread is taken out of a thread pool, this method will return the thread pool. |
|
|
enqueue(Callable<T> t)
Submits a value-returning task for execution and returns a Future representing the pending results of the task. |
|
Future<?> |
enqueue(Runnable r)
Submits a Runnable task for execution and returns a Future representing that task. |
|
protected void |
finalize()
|
|
int |
getMaxThreads()
Returns the maximum number of threads in the pool. |
|
(package private) int |
getQueueSize()
Returns the size of the future queue (needed by the unit test). |
|
int |
getRunningThreads()
Returns the number of currently running threads in this pool and its sub pools. |
|
void |
interruptAll()
Interrupts all running jobs. |
|
|
runInvisible(Callable<T> r)
Executes the runnable in the current thread. |
|
void |
setMaxThreads(int newValue)
Sets the maximum number of threads in the pool. |
|
void |
shutdown()
Shuts the pool down, still running threads are not interrupted. |
|
|
submit(Callable<T> task)
Submits a value-returning task for execution and returns a Future representing the pending results of the task. |
|
Future<?> |
submit(Runnable task)
Submits a Runnable task for execution and returns a Future representing that task. |
|
|
trySubmit(Callable<T> t)
Tries to submits a value-returning task for immediate execution and returns a Future representing the pending results of the task if a thread is free. |
|
Future<?> |
trySubmit(Runnable r)
Tries to submits a Runnable task for immediate execution and returns a Future representing the task if a thread is free. |
|
void |
waitForTermination()
Waits until all jobs in this pool and its sub pools have been finished. |
|
protected void |
workerFinished(org.knime.core.util.ThreadPool.Worker w)
This method is called every time a worker has finished. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ThreadPool(int maxThreads)
maxThreads - the maximum number of threads
protected ThreadPool(int maxThreads,
ThreadPool parent)
maxThreads - the maximum number of threads in the poolparent - the parent pool| Method Detail |
|---|
public ThreadPool createSubPool()
public ThreadPool createSubPool(int maxThreads)
maxThreads - the maximum number of threads in the sub pool
public <T> Future<T> enqueue(Callable<T> t)
If you would like to immediately block waiting for a task, you can use constructions of the form result = exec.submit(aCallable).get();
Note: The Executors class includes a set of
methods that can convert some other common closure-like objects, for
example, PrivilegedAction to Callable form
so they can be submitted.
T - any result typet - the task to submit
NullPointerException - if task nullsubmit(Callable)public Future<?> enqueue(Runnable r)
r - the task to submit
NullPointerException - if task nullsubmit(Runnable)public <T> Future<T> trySubmit(Callable<T> t)
null is
returned and the task is not queued.
If you would like to immediately block waiting for a task, you can use constructions of the form result = exec.submit(aCallable).get();
Note: The Executors class includes a set of
methods that can convert some other common closure-like objects, for
example, PrivilegedAction to Callable form
so they can be submitted.
T - any result typet - the task to submit
null if no thread was available
NullPointerException - if task nullsubmit(Callable)public Future<?> trySubmit(Runnable r)
null is returned and the task is not
queued.
r - the task to submit
NullPointerException - if task nullsubmit(Runnable)public int getMaxThreads()
public int getRunningThreads()
public <T> T runInvisible(Callable<T> r)
throws ExecutionException
T - Type of the argument (result type)r - A callable, which will be executed by the thread invoking this
method.
IllegalThreadStateException - if the current thread is not taken
out of a thread pool
ExecutionException - if the callable could not be executed for some
reasonpublic void setMaxThreads(int newValue)
newValue - the new maximum thread numberpublic void shutdown()
public void interruptAll()
public <T> Future<T> submit(Callable<T> task)
throws InterruptedException
If you would like to immediately block waiting for a task, you can use constructions of the form result = exec.submit(aCallable).get();
Note: The Executors class includes a set of
methods that can convert some other common closure-like objects, for
example, PrivilegedAction to Callable form
so they can be submitted.
T - any result typetask - the task to submit
NullPointerException - if task null
InterruptedException - if the thread is interruptedenqueue(Callable)
public Future<?> submit(Runnable task)
throws InterruptedException
task - the task to submit
NullPointerException - if task null
InterruptedException - if the thread is interruptedenqueue(Runnable)
public void waitForTermination()
throws InterruptedException
InterruptedException - if the thread is interrupted while waitingprotected void workerFinished(org.knime.core.util.ThreadPool.Worker w)
w - the finished worker
protected void finalize()
throws Throwable
finalize in class ObjectThrowablepublic static ThreadPool currentPool()
null.
nullint getQueueSize()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||