public class ThreadUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.util.concurrent.ThreadPoolExecutor |
threadPoolExecutor
The threadPoolExecutor holds at least as many threads for parallel execution as the number of
processors; additional threads are added as required.
|
Constructor and Description |
---|
ThreadUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Thread[] |
createThreadArray() |
static java.lang.Thread[] |
createThreadArray(int nb) |
static int |
getNbCpus() |
static void |
joinAll(java.util.concurrent.Future[] futures)
Waits for completion of all
Callable s corresponding to the
Future s given. |
static java.util.concurrent.Future[] |
start(java.util.concurrent.Callable[] callables)
Starts all callables for parallel execution (using a ThreadPoolExecutor)
without waiting for the results.
|
static java.util.concurrent.Future[] |
startAndJoin(java.util.concurrent.Callable[] callables)
Starts all callables for parallel execution (using a ThreadPoolExecutor)
and waits until each of them has finished.
|
static void |
startAndJoin(java.lang.Thread[] threads)
Start all given threads and wait on each of them until all are done.
|
public static java.util.concurrent.ThreadPoolExecutor threadPoolExecutor
public static void startAndJoin(java.lang.Thread[] threads)
threads
- public static java.lang.Thread[] createThreadArray(int nb)
public static java.lang.Thread[] createThreadArray()
public static int getNbCpus()
public static java.util.concurrent.Future[] startAndJoin(java.util.concurrent.Callable[] callables)
callables
- Array of tasks. If no return value is needed,
best use Callable
(then the Void call()
method
should return null). If the array size is 1, the call()
method
is executed in the current thread.java.util.concurrent.Future
s,
corresponding to the callables. If the call methods of the callables
return results, the get() methods of these Futures may be used to get the results.public static java.util.concurrent.Future[] start(java.util.concurrent.Callable[] callables)
callables
- Array of tasks; these might be Callable
if no return value is needed (then the call
methods should
return null).java.util.concurrent.Future
s,
corresponding to the callables. The futures may be used to wait for
completion of the callables or cancel them.
If the call methods of the callables return results, these Futures
may be used to get the results.public static void joinAll(java.util.concurrent.Future[] futures)
Callable
s corresponding to the
Future
s given.
If the current thread is interrupted, each of the Callable
s
gets cancelled and interrupted. Also in that case, this method waits
until all callables have finished.
The 'interrupted' status of the current thread is preserved,
as required for preview in an ImageJ ExtendedPlugInFilter.