List of utility methods to do Thread Future
CompletableFuture
| sequence(List sequence CompletableFuture<Void> allDoneFuture = CompletableFuture .allOf(futures.toArray(new CompletableFuture[futures.size()])); return allDoneFuture .thenApply(v -> futures.stream().map(CompletableFuture::join).collect(Collectors.<T>toList())); |
CompletableFuture
| sequence(List sequence CompletableFuture<Void> allDoneFuture = CompletableFuture .allOf(futures.toArray(new CompletableFuture[futures.size()])); return allDoneFuture .thenApply(v -> futures.stream().map(future -> future.join()).collect(Collectors.<T>toList())); |
CompletableFuture
| sequence(List sequence if (futures.isEmpty()) { return CompletableFuture.completedFuture(Collections.emptyList()); CompletableFuture[] fa = futures.toArray(new CompletableFuture[futures.size()]); return CompletableFuture.allOf(fa).thenApply(v -> { List<T> results = new ArrayList<>(futures.size()); for (CompletableFuture<T> cf : futures) { results.add(cf.join()); ... |
CompletableFuture
| sequence(List sequence return CompletableFuture
.supplyAsync(() -> futures.stream().map(future -> future.join()).collect(Collectors.<T>toList()));
|
List | submitTasks(ExecutorCompletionService submit Tasks List<Future<V>> futures = new LinkedList<Future<V>>(); if (tasks != null) { for (Callable<V> callable : tasks) { futures.add(ecs.submit(callable)); return futures; |
long | sumFutures(List Given futures from the various ThreadServiceStats, wait for them to finish and add their numeric values together. long total = 0; for (Future<Object> f : futures) { try { total += (Long) f.get(); } catch (Exception ignore) { System.out.println("### sumFutures got exception!"); return total; |
void | transferResult(final CompletionStage transfer Result source.whenComplete((result, throwable) -> { final boolean isSuccessful = throwable == null; if (isSuccessful) { target.complete(result); } else { target.completeExceptionally(throwable); }); ... |
void | transferResult(final CompletionStage Internal JVM SDK util. source.whenCompleteAsync((result, throwable) -> { final boolean isSuccessful = throwable == null; if (isSuccessful) { target.complete(result); } else { target.completeExceptionally(throwable); }); ... |
void | unwrap(Throwable throwable, Class throwableA) Unwraps ExecutionException thrown from a CompletableFuture. Throwable unwrapThrowable = throwable; if (throwable instanceof ExecutionException || throwable instanceof CompletionException) { unwrapThrowable = throwable.getCause(); if (throwableA.isInstance(unwrapThrowable)) { throw (A) unwrapThrowable; if (unwrapThrowable instanceof RuntimeException) { ... |
T | waitFor(Future wait For boolean interrupted = false; try { while (true) { try { return future.get(); } catch (InterruptedException e) { interrupted = true; } finally { if (interrupted) { Thread.currentThread().interrupt(); |