- java.lang.Object
-
- ij.util.ThreadUtil
-
public class ThreadUtil extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description ThreadUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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 allCallable
s corresponding to theFuture
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 void
startAndJoin(java.lang.Thread[] threads)
Start all given threads and wait on each of them until all are done.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.
-
-
-
Field Detail
-
threadPoolExecutor
public 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. These additional threads will be terminated if idle for 120 seconds.
-
-
Method Detail
-
startAndJoin
public static void startAndJoin(java.lang.Thread[] threads)
Start all given threads and wait on each of them until all are done. From Stephan Preibisch's Multithreading.java class. See: http://repo.or.cz/w/trakem2.git?a=blob;f=mpi/fruitfly/general/MultiThreading.java;hb=HEAD- Parameters:
threads
-
-
createThreadArray
public static java.lang.Thread[] createThreadArray(int nb)
-
createThreadArray
public static java.lang.Thread[] createThreadArray()
-
getNbCpus
public static int getNbCpus()
-
startAndJoin
public 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. If the current thread is interrupted, each of the callables gets cancelled and interrupted. Also in that case, waits until all callables have finished. The 'interrupted' status of the current thread is preserved, as required for preview in an ImageJ ExtendedPlugInFilter. Note that ImageJ requires that all callables can run concurrently, and none of them must stay in the queue while others run. (This is required by the RankFilters, where the threads are not independent)- Parameters:
callables
- Array of tasks. If no return value is needed, best useCallable
(then theVoid call()
method should return null). If the array size is 1, thecall()
method is executed in the current thread.- Returns:
- Array of the
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.
-
start
public 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.- Parameters:
callables
- Array of tasks; these might beCallable
if no return value is needed (then thecall
methods should return null).- Returns:
- Array of the
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.
-
joinAll
public static void joinAll(java.util.concurrent.Future[] futures)
Waits for completion of allCallable
s corresponding to theFuture
s given. If the current thread is interrupted, each of theCallable
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.
-
-