Class FutureUtils

java.lang.Object
ubic.gemma.core.util.concurrent.FutureUtils

public class FutureUtils extends Object
  • Constructor Details

    • FutureUtils

      public FutureUtils()
  • Method Details

    • get

      public static <T> T get(Future<T> future)
      Resolve a future silently, turning any exception into an unchecked RuntimeException.
    • 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() and CompletableFuture should be considered for more complex workloads.

      Parameters:
      func - function to apply
      collection - collection of elements to process
      executorService - an executor service for running the tasks
      mayInterruptIfRunning - if true, the remaining tasks will be interrupted if they are running as per Future.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: