package ij.util;
public class ThreadUtil {
public static void startAndJoin(Thread[] threads) {
for (int ithread = 0; ithread < threads.length; ++ithread) {
threads[ithread].setPriority(Thread.NORM_PRIORITY);
threads[ithread].start();
}
try {
for (int ithread = 0; ithread < threads.length; ++ithread) {
threads[ithread].join();
}
} catch (InterruptedException ie) {
throw new RuntimeException(ie);
}
}
public static Thread[] createThreadArray(int nb) {
if (nb == 0) {
nb = getNbCpus();
}
Thread[] threads = new Thread[nb];
return threads;
}
public static Thread[] createThreadArray() {
return createThreadArray(0);
}
public static int getNbCpus() {
return Runtime.getRuntime().availableProcessors();
}
}