devutility.internal.util.concurrent.ConcurrentExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of devutility.internal Show documentation
Show all versions of devutility.internal Show documentation
Utilities for Java development
package devutility.internal.util.concurrent;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
public class ConcurrentExecutor {
/**
* Run list of callables, return futures after runing completely.
* @param callables: Callable list
* @return {@code List>}
* @throws InterruptedException
*/
public static List> run(List> callables) throws InterruptedException {
ExecutorService executorService = ExecutorServiceUtils.threadPoolExecutor();
if (executorService == null) {
return new ArrayList<>();
}
return executorService.invokeAll(callables);
}
/**
* Run callables and return their results.
* @param callables: Callable list
* @return {@code List}
* @throws InterruptedException
* @throws ExecutionException
*/
public static List runAndGet(List> callables) throws InterruptedException, ExecutionException {
List list = new ArrayList<>(callables.size());
List> futures = run(callables);
for (Future future : futures) {
list.add(future.get());
}
return list;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy