List of utility methods to do Thread Future
CompletableFuture | exceptionallyCompletedFuture(final Throwable e) Creates a CompletableFuture which is completed exceptionally with the given Exception. return failed(e);
|
CompletionStage | exceptionallyCompletedFuture(final Throwable t) exceptionally Completed Future CompletableFuture<T> future = new CompletableFuture<>(); future.completeExceptionally(t); return future; |
void | getAll(List get All for (final Future future : futures) { try { future.get(); } catch (ExecutionException | InterruptedException e) { throw new RuntimeException(e); |
List | getAll(List get All try { List<T> result = new ArrayList<T>(futures.size()); for (Future<T> future : futures) { result.add(future.get()); return result; } catch (Exception e) { throw new RuntimeException("Exception while getting result of multiple futures", e); ... |
List | getAllDone(Collection Get all futures that are done List<Future> doneFutures = new ArrayList<Future>(); for (Future f : futures) { if (f.isDone()) { doneFutures.add(f); return doneFutures; |
Throwable | getExceptionFromNewThread(String threadName, Runnable target) get Exception From New Thread try { runInNewThread(threadName, target); } catch (Throwable throwable) { return throwable; throw new AssertionError("Expected to throw an exception but did not throw anything"); |
CompletableFuture | getFailedFuture(Throwable throwable) Returns a CompletableFuture that has failed with the exception provided as argument. CompletableFuture<T> failedAttempt = new CompletableFuture<>(); failedAttempt.completeExceptionally(throwable); return failedAttempt; |
T | getFuture(Future Retrieves the value of a Future and throws AssertionError on failures. try { return future.get(); } catch (InterruptedException e) { throw new AssertionError(message + " " + e.getMessage()); } catch (ExecutionException e) { throw new AssertionError(message + " " + e.getMessage()); |
long | getMinIn(Map get Min In Iterable<Long> collection = Iterables.transform(responses.values(), new Function<Future<Long>, Long>() { @Override public Long apply(Future<Long> from) { try { return from.get(); } catch (InterruptedException e) { } catch (ExecutionException e) { return null; }); long time = Collections.min(Sets.newHashSet(collection)); return time; |
List | getResults(Iterable Checks results for exceptions by calling all Future#get() . List<T> results = new ArrayList<>(); for (Future<T> future : futures) { try { results.add(future.get()); } catch (InterruptedException e) { throw new IllegalStateException(e); } catch (ExecutionException e) { throw new IllegalStateException(e.getCause()); ... |