Package ubic.gemma.core.util.concurrent
Class FutureUtils
java.lang.Object
ubic.gemma.core.util.concurrent.FutureUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TResolve a future silently, turning any exception into an uncheckedRuntimeException.static <T,U> List <U> parallelMap(Function<T, U> func, List<T> collection, ExecutorService executorService, boolean mayInterruptIfRunning) Map a function over a collection in parallel.static <U> List<U> parallelMapRange(IntFunction<U> func, int startInclusive, int endExclusive, ExecutorService executorService, boolean mayInterruptIfRunning) Map a function over a range of integers in parallel.
-
Constructor Details
-
FutureUtils
public FutureUtils()
-
-
Method Details
-
get
Resolve a future silently, turning any exception into an uncheckedRuntimeException. -
parallelMap
public static <T,U> List<U> parallelMap(Function<T, U> func, List<T> collection, ExecutorService executorService, boolean mayInterruptIfRunning) Map a function over a collection in parallel.If any of the call fails, all the pending jobs are cancelled. When that happens, you may control whether to interrupt running tasks with the mayInterruptIfRunning parameter.
Use this for simple parallelization scenarios. Alternatives such as
BaseStream.parallel()andCompletableFutureshould be considered for more complex workloads.- Parameters:
func- function to applycollection- collection of elements to processexecutorService- an executor service for running the tasksmayInterruptIfRunning- if true, the remaining tasks will be interrupted if they are running as perFuture.cancel(boolean)
-
parallelMapRange
public static <U> List<U> parallelMapRange(IntFunction<U> func, int startInclusive, int endExclusive, ExecutorService executorService, boolean mayInterruptIfRunning) Map a function over a range of integers in parallel.- See Also:
-