CompletableFuture (Java SE 9 & JDK 9 ) (original) (raw)
Nested Class Summary
Nested Classes
Modifier and Type Class Description static interface CompletableFuture.AsynchronousCompletionTask A marker interface identifying asynchronous tasks produced byasync methods. Constructor Summary
Constructors
Constructor Description CompletableFuture() Creates a new incomplete CompletableFuture. Method Summary
All Methods Static Methods Instance Methods Concrete Methods
Modifier and Type Method Description CompletableFuture<Void> acceptEither(CompletionStage<? extends T> other,Consumer<? super T> action) Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied action. CompletableFuture<Void> acceptEitherAsync(CompletionStage<? extends T> other,Consumer<? super T> action) Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using this stage's default asynchronous execution facility, with the corresponding result as argument to the supplied action. CompletableFuture<Void> acceptEitherAsync(CompletionStage<? extends T> other,Consumer<? super T> action,Executor executor) Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied action. static CompletableFuture<Void> allOf(CompletableFuture<?>... cfs) Returns a new CompletableFuture that is completed when all of the given CompletableFutures complete. static CompletableFuture<Object> anyOf(CompletableFuture<?>... cfs) Returns a new CompletableFuture that is completed when any of the given CompletableFutures complete, with the same result. CompletableFuture applyToEither(CompletionStage<? extends T> other,Function<? super T,U> fn) Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied function. CompletableFuture applyToEitherAsync(CompletionStage<? extends T> other,Function<? super T,U> fn) Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using this stage's default asynchronous execution facility, with the corresponding result as argument to the supplied function. CompletableFuture applyToEitherAsync(CompletionStage<? extends T> other,Function<? super T,U> fn,Executor executor) Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied function. boolean cancel(boolean mayInterruptIfRunning) If not already completed, completes this CompletableFuture with a CancellationException. boolean complete(T value) If not already completed, sets the value returned by get() and related methods to the given value. CompletableFuture<T> completeAsync(Supplier<? extends T> supplier) Completes this CompletableFuture with the result of the given Supplier function invoked from an asynchronous task using the default executor. CompletableFuture<T> completeAsync(Supplier<? extends T> supplier,Executor executor) Completes this CompletableFuture with the result of the given Supplier function invoked from an asynchronous task using the given executor. static CompletableFuture completedFuture(U value) Returns a new CompletableFuture that is already completed with the given value. static CompletionStage completedStage(U value) Returns a new CompletionStage that is already completed with the given value and supports only those methods in interface CompletionStage. boolean completeExceptionally(Throwable ex) If not already completed, causes invocations of get() and related methods to throw the given exception. CompletableFuture<T> completeOnTimeout(T value, long timeout,TimeUnit unit) Completes this CompletableFuture with the given value if not otherwise completed before the given timeout. CompletableFuture<T> copy() Returns a new CompletableFuture that is completed normally with the same value as this CompletableFuture when it completes normally. Executor defaultExecutor() Returns the default Executor used for async methods that do not specify an Executor. static Executor delayedExecutor(long delay,TimeUnit unit) Returns a new Executor that submits a task to the default executor after the given delay (or no delay if non-positive). static Executor delayedExecutor(long delay,TimeUnit unit,Executor executor) Returns a new Executor that submits a task to the given base executor after the given delay (or no delay if non-positive). CompletableFuture<T> exceptionally(Function<Throwable,? extends T> fn) Returns a new CompletableFuture that is completed when this CompletableFuture completes, with the result of the given function of the exception triggering this CompletableFuture's completion when it completes exceptionally; otherwise, if this CompletableFuture completes normally, then the returned CompletableFuture also completes normally with the same value. static CompletableFuture failedFuture(Throwable ex) Returns a new CompletableFuture that is already completed exceptionally with the given exception. static CompletionStage failedStage(Throwable ex) Returns a new CompletionStage that is already completed exceptionally with the given exception and supports only those methods in interface CompletionStage. T get() Waits if necessary for this future to complete, and then returns its result. T get(long timeout,TimeUnit unit) Waits if necessary for at most the given time for this future to complete, and then returns its result, if available. T getNow(T valueIfAbsent) Returns the result value (or throws any encountered exception) if completed, else returns the given valueIfAbsent. int getNumberOfDependents() Returns the estimated number of CompletableFutures whose completions are awaiting completion of this CompletableFuture. CompletableFuture handle(BiFunction<? super T,Throwable,? extends U> fn) Returns a new CompletionStage that, when this stage completes either normally or exceptionally, is executed with this stage's result and exception as arguments to the supplied function. CompletableFuture handleAsync(BiFunction<? super T,Throwable,? extends U> fn) Returns a new CompletionStage that, when this stage completes either normally or exceptionally, is executed using this stage's default asynchronous execution facility, with this stage's result and exception as arguments to the supplied function. CompletableFuture handleAsync(BiFunction<? super T,Throwable,? extends U> fn,Executor executor) Returns a new CompletionStage that, when this stage completes either normally or exceptionally, is executed using the supplied executor, with this stage's result and exception as arguments to the supplied function. boolean isCancelled() Returns true if this CompletableFuture was cancelled before it completed normally. boolean isCompletedExceptionally() Returns true if this CompletableFuture completed exceptionally, in any way. boolean isDone() Returns true if completed in any fashion: normally, exceptionally, or via cancellation. T join() Returns the result value when complete, or throws an (unchecked) exception if completed exceptionally. CompletionStage<T> minimalCompletionStage() Returns a new CompletionStage that is completed normally with the same value as this CompletableFuture when it completes normally, and cannot be independently completed or otherwise used in ways not defined by the methods of interface CompletionStage. CompletableFuture newIncompleteFuture() Returns a new incomplete CompletableFuture of the type to be returned by a CompletionStage method. void obtrudeException(Throwable ex) Forcibly causes subsequent invocations of method get() and related methods to throw the given exception, whether or not already completed. void obtrudeValue(T value) Forcibly sets or resets the value subsequently returned by method get() and related methods, whether or not already completed. CompletableFuture<T> orTimeout(long timeout,TimeUnit unit) Exceptionally completes this CompletableFuture with a TimeoutException if not otherwise completed before the given timeout. CompletableFuture<Void> runAfterBoth(CompletionStage<?> other,Runnable action) Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action. CompletableFuture<Void> runAfterBothAsync(CompletionStage<?> other,Runnable action) Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action using this stage's default asynchronous execution facility. CompletableFuture<Void> runAfterBothAsync(CompletionStage<?> other,Runnable action,Executor executor) Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action using the supplied executor. CompletableFuture<Void> runAfterEither(CompletionStage<?> other,Runnable action) Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action. CompletableFuture<Void> runAfterEitherAsync(CompletionStage<?> other,Runnable action) Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action using this stage's default asynchronous execution facility. CompletableFuture<Void> runAfterEitherAsync(CompletionStage<?> other,Runnable action,Executor executor) Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action using the supplied executor. static CompletableFuture<Void> runAsync(Runnable runnable) Returns a new CompletableFuture that is asynchronously completed by a task running in the ForkJoinPool.commonPool() after it runs the given action. static CompletableFuture<Void> runAsync(Runnable runnable,Executor executor) Returns a new CompletableFuture that is asynchronously completed by a task running in the given executor after it runs the given action. static CompletableFuture supplyAsync(Supplier supplier) Returns a new CompletableFuture that is asynchronously completed by a task running in the ForkJoinPool.commonPool() with the value obtained by calling the given Supplier. static CompletableFuture supplyAsync(Supplier supplier,Executor executor) Returns a new CompletableFuture that is asynchronously completed by a task running in the given executor with the value obtained by calling the given Supplier. CompletableFuture<Void> thenAccept(Consumer<? super T> action) Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied action. CompletableFuture<Void> thenAcceptAsync(Consumer<? super T> action) Returns a new CompletionStage that, when this stage completes normally, is executed using this stage's default asynchronous execution facility, with this stage's result as the argument to the supplied action. CompletableFuture<Void> thenAcceptAsync(Consumer<? super T> action,Executor executor) Returns a new CompletionStage that, when this stage completes normally, is executed using the supplied Executor, with this stage's result as the argument to the supplied action. CompletableFuture<Void> thenAcceptBoth(CompletionStage<? extends U> other,BiConsumer<? super T,? super U> action) Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied action. CompletableFuture<Void> thenAcceptBothAsync(CompletionStage<? extends U> other,BiConsumer<? super T,? super U> action) Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using this stage's default asynchronous execution facility, with the two results as arguments to the supplied action. CompletableFuture<Void> thenAcceptBothAsync(CompletionStage<? extends U> other,BiConsumer<? super T,? super U> action,Executor executor) Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied action. CompletableFuture thenApply(Function<? super T,? extends U> fn) Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied function. CompletableFuture thenApplyAsync(Function<? super T,? extends U> fn) Returns a new CompletionStage that, when this stage completes normally, is executed using this stage's default asynchronous execution facility, with this stage's result as the argument to the supplied function. CompletableFuture thenApplyAsync(Function<? super T,? extends U> fn,Executor executor) Returns a new CompletionStage that, when this stage completes normally, is executed using the supplied Executor, with this stage's result as the argument to the supplied function. <U,V> CompletableFuture thenCombine(CompletionStage<? extends U> other,BiFunction<? super T,? super U,? extends V> fn) Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied function. <U,V> CompletableFuture thenCombineAsync(CompletionStage<? extends U> other,BiFunction<? super T,? super U,? extends V> fn) Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using this stage's default asynchronous execution facility, with the two results as arguments to the supplied function. <U,V> CompletableFuture thenCombineAsync(CompletionStage<? extends U> other,BiFunction<? super T,? super U,? extends V> fn,Executor executor) Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied function. CompletableFuture thenCompose(Function<? super T,? extends CompletionStage> fn) Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function. CompletableFuture thenComposeAsync(Function<? super T,? extends CompletionStage> fn) Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function, executed using this stage's default asynchronous execution facility. CompletableFuture thenComposeAsync(Function<? super T,? extends CompletionStage> fn,Executor executor) Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function, executed using the supplied Executor. CompletableFuture<Void> thenRun(Runnable action) Returns a new CompletionStage that, when this stage completes normally, executes the given action. CompletableFuture<Void> thenRunAsync(Runnable action) Returns a new CompletionStage that, when this stage completes normally, executes the given action using this stage's default asynchronous execution facility. CompletableFuture<Void> thenRunAsync(Runnable action,Executor executor) Returns a new CompletionStage that, when this stage completes normally, executes the given action using the supplied Executor. CompletableFuture<T> toCompletableFuture() Returns this CompletableFuture. String toString() Returns a string identifying this CompletableFuture, as well as its completion state. CompletableFuture<T> whenComplete(BiConsumer<? super T,? super Throwable> action) Returns a new CompletionStage with the same result or exception as this stage, that executes the given action when this stage completes. CompletableFuture<T> whenCompleteAsync(BiConsumer<? super T,? super Throwable> action) Returns a new CompletionStage with the same result or exception as this stage, that executes the given action using this stage's default asynchronous execution facility when this stage completes. CompletableFuture<T> whenCompleteAsync(BiConsumer<? super T,? super Throwable> action,Executor executor) Returns a new CompletionStage with the same result or exception as this stage, that executes the given action using the supplied Executor when this stage completes. * ### Methods inherited from class java.lang.[Object](../../../java/lang/Object.html "class in java.lang") `[clone](../../../java/lang/Object.html#clone--), [equals](../../../java/lang/Object.html#equals-java.lang.Object-), [finalize](../../../java/lang/Object.html#finalize--), [getClass](../../../java/lang/Object.html#getClass--), [hashCode](../../../java/lang/Object.html#hashCode--), [notify](../../../java/lang/Object.html#notify--), [notifyAll](../../../java/lang/Object.html#notifyAll--), [wait](../../../java/lang/Object.html#wait--), [wait](../../../java/lang/Object.html#wait-long-), [wait](../../../java/lang/Object.html#wait-long-int-)`
Constructor Detail
* #### CompletableFuture public CompletableFuture() Creates a new incomplete CompletableFuture.
Method Detail
* #### supplyAsync public static <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> supplyAsync([Supplier](../../../java/util/function/Supplier.html "interface in java.util.function")<U> supplier) Returns a new CompletableFuture that is asynchronously completed by a task running in the [ForkJoinPool.commonPool()](../../../java/util/concurrent/ForkJoinPool.html#commonPool--) with the value obtained by calling the given Supplier. Type Parameters: `U` \- the function's return type Parameters: `supplier` \- a function returning the value to be used to complete the returned CompletableFuture Returns: the new CompletableFuture * #### supplyAsync public static <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> supplyAsync([Supplier](../../../java/util/function/Supplier.html "interface in java.util.function")<U> supplier, [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") executor) Returns a new CompletableFuture that is asynchronously completed by a task running in the given executor with the value obtained by calling the given Supplier. Type Parameters: `U` \- the function's return type Parameters: `supplier` \- a function returning the value to be used to complete the returned CompletableFuture `executor` \- the executor to use for asynchronous execution Returns: the new CompletableFuture * #### runAsync public static [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> runAsync([Runnable](../../../java/lang/Runnable.html "interface in java.lang") runnable) Returns a new CompletableFuture that is asynchronously completed by a task running in the [ForkJoinPool.commonPool()](../../../java/util/concurrent/ForkJoinPool.html#commonPool--) after it runs the given action. Parameters: `runnable` \- the action to run before completing the returned CompletableFuture Returns: the new CompletableFuture * #### runAsync public static [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> runAsync([Runnable](../../../java/lang/Runnable.html "interface in java.lang") runnable, [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") executor) Returns a new CompletableFuture that is asynchronously completed by a task running in the given executor after it runs the given action. Parameters: `runnable` \- the action to run before completing the returned CompletableFuture `executor` \- the executor to use for asynchronous execution Returns: the new CompletableFuture * #### completedFuture public static <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> completedFuture(U value) Returns a new CompletableFuture that is already completed with the given value. Type Parameters: `U` \- the type of the value Parameters: `value` \- the value Returns: the completed CompletableFuture * #### isDone public boolean isDone() Returns `true` if completed in any fashion: normally, exceptionally, or via cancellation. Specified by: `[isDone](../../../java/util/concurrent/Future.html#isDone--)` in interface `[Future](../../../java/util/concurrent/Future.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Returns: `true` if completed * #### get public [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture") get() throws [InterruptedException](../../../java/lang/InterruptedException.html "class in java.lang"), [ExecutionException](../../../java/util/concurrent/ExecutionException.html "class in java.util.concurrent") Waits if necessary for this future to complete, and then returns its result. Specified by: `[get](../../../java/util/concurrent/Future.html#get--)` in interface `[Future](../../../java/util/concurrent/Future.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Returns: the result value Throws: `[CancellationException](../../../java/util/concurrent/CancellationException.html "class in java.util.concurrent")` \- if this future was cancelled `[ExecutionException](../../../java/util/concurrent/ExecutionException.html "class in java.util.concurrent")` \- if this future completed exceptionally `[InterruptedException](../../../java/lang/InterruptedException.html "class in java.lang")` \- if the current thread was interrupted while waiting * #### get public [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture") get(long timeout, [TimeUnit](../../../java/util/concurrent/TimeUnit.html "enum in java.util.concurrent") unit) throws [InterruptedException](../../../java/lang/InterruptedException.html "class in java.lang"), [ExecutionException](../../../java/util/concurrent/ExecutionException.html "class in java.util.concurrent"), [TimeoutException](../../../java/util/concurrent/TimeoutException.html "class in java.util.concurrent") Waits if necessary for at most the given time for this future to complete, and then returns its result, if available. Specified by: `[get](../../../java/util/concurrent/Future.html#get-long-java.util.concurrent.TimeUnit-)` in interface `[Future](../../../java/util/concurrent/Future.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `timeout` \- the maximum time to wait `unit` \- the time unit of the timeout argument Returns: the result value Throws: `[CancellationException](../../../java/util/concurrent/CancellationException.html "class in java.util.concurrent")` \- if this future was cancelled `[ExecutionException](../../../java/util/concurrent/ExecutionException.html "class in java.util.concurrent")` \- if this future completed exceptionally `[InterruptedException](../../../java/lang/InterruptedException.html "class in java.lang")` \- if the current thread was interrupted while waiting `[TimeoutException](../../../java/util/concurrent/TimeoutException.html "class in java.util.concurrent")` \- if the wait timed out * #### join public [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture") join() Returns the result value when complete, or throws an (unchecked) exception if completed exceptionally. To better conform with the use of common functional forms, if a computation involved in the completion of this CompletableFuture threw an exception, this method throws an (unchecked) [CompletionException](../../../java/util/concurrent/CompletionException.html "class in java.util.concurrent") with the underlying exception as its cause. Returns: the result value Throws: `[CancellationException](../../../java/util/concurrent/CancellationException.html "class in java.util.concurrent")` \- if the computation was cancelled `[CompletionException](../../../java/util/concurrent/CompletionException.html "class in java.util.concurrent")` \- if this future completed exceptionally or a completion computation threw an exception * #### getNow public [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture") getNow([T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture") valueIfAbsent) Returns the result value (or throws any encountered exception) if completed, else returns the given valueIfAbsent. Parameters: `valueIfAbsent` \- the value to return if not completed Returns: the result value, if completed, else the given valueIfAbsent Throws: `[CancellationException](../../../java/util/concurrent/CancellationException.html "class in java.util.concurrent")` \- if the computation was cancelled `[CompletionException](../../../java/util/concurrent/CompletionException.html "class in java.util.concurrent")` \- if this future completed exceptionally or a completion computation threw an exception * #### complete public boolean complete([T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture") value) If not already completed, sets the value returned by [get()](../../../java/util/concurrent/CompletableFuture.html#get--) and related methods to the given value. Parameters: `value` \- the result value Returns: `true` if this invocation caused this CompletableFuture to transition to a completed state, else `false` * #### completeExceptionally public boolean completeExceptionally([Throwable](../../../java/lang/Throwable.html "class in java.lang") ex) If not already completed, causes invocations of [get()](../../../java/util/concurrent/CompletableFuture.html#get--) and related methods to throw the given exception. Parameters: `ex` \- the exception Returns: `true` if this invocation caused this CompletableFuture to transition to a completed state, else `false` * #### thenApply public <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> thenApply([Function](../../../java/util/function/Function.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),? extends U> fn) Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied function. This method is analogous to[Optional.map](../../../java/util/Optional.html#map-java.util.function.Function-) and[Stream.map](../../../java/util/stream/Stream.html#map-java.util.function.Function-). See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenApply](../../../java/util/concurrent/CompletionStage.html#thenApply-java.util.function.Function-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the function's return type Parameters: `fn` \- the function to use to compute the value of the returned CompletionStage Returns: the new CompletionStage * #### thenApplyAsync public <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> thenApplyAsync([Function](../../../java/util/function/Function.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),? extends U> fn) Returns a new CompletionStage that, when this stage completes normally, is executed using this stage's default asynchronous execution facility, with this stage's result as the argument to the supplied function. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenApplyAsync](../../../java/util/concurrent/CompletionStage.html#thenApplyAsync-java.util.function.Function-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the function's return type Parameters: `fn` \- the function to use to compute the value of the returned CompletionStage Returns: the new CompletionStage * #### thenApplyAsync public <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> thenApplyAsync([Function](../../../java/util/function/Function.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),? extends U> fn, [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") executor) Returns a new CompletionStage that, when this stage completes normally, is executed using the supplied Executor, with this stage's result as the argument to the supplied function. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenApplyAsync](../../../java/util/concurrent/CompletionStage.html#thenApplyAsync-java.util.function.Function-java.util.concurrent.Executor-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the function's return type Parameters: `fn` \- the function to use to compute the value of the returned CompletionStage `executor` \- the executor to use for asynchronous execution Returns: the new CompletionStage * #### thenAccept public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> thenAccept([Consumer](../../../java/util/function/Consumer.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> action) Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied action. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenAccept](../../../java/util/concurrent/CompletionStage.html#thenAccept-java.util.function.Consumer-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `action` \- the action to perform before completing the returned CompletionStage Returns: the new CompletionStage * #### thenAcceptAsync public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> thenAcceptAsync([Consumer](../../../java/util/function/Consumer.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> action) Returns a new CompletionStage that, when this stage completes normally, is executed using this stage's default asynchronous execution facility, with this stage's result as the argument to the supplied action. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenAcceptAsync](../../../java/util/concurrent/CompletionStage.html#thenAcceptAsync-java.util.function.Consumer-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `action` \- the action to perform before completing the returned CompletionStage Returns: the new CompletionStage * #### thenAcceptAsync public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> thenAcceptAsync([Consumer](../../../java/util/function/Consumer.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> action, [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") executor) Returns a new CompletionStage that, when this stage completes normally, is executed using the supplied Executor, with this stage's result as the argument to the supplied action. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenAcceptAsync](../../../java/util/concurrent/CompletionStage.html#thenAcceptAsync-java.util.function.Consumer-java.util.concurrent.Executor-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `action` \- the action to perform before completing the returned CompletionStage `executor` \- the executor to use for asynchronous execution Returns: the new CompletionStage * #### thenRun public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> thenRun([Runnable](../../../java/lang/Runnable.html "interface in java.lang") action) Returns a new CompletionStage that, when this stage completes normally, executes the given action. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenRun](../../../java/util/concurrent/CompletionStage.html#thenRun-java.lang.Runnable-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `action` \- the action to perform before completing the returned CompletionStage Returns: the new CompletionStage * #### thenRunAsync public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> thenRunAsync([Runnable](../../../java/lang/Runnable.html "interface in java.lang") action) Returns a new CompletionStage that, when this stage completes normally, executes the given action using this stage's default asynchronous execution facility. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenRunAsync](../../../java/util/concurrent/CompletionStage.html#thenRunAsync-java.lang.Runnable-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `action` \- the action to perform before completing the returned CompletionStage Returns: the new CompletionStage * #### thenRunAsync public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> thenRunAsync([Runnable](../../../java/lang/Runnable.html "interface in java.lang") action, [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") executor) Returns a new CompletionStage that, when this stage completes normally, executes the given action using the supplied Executor. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenRunAsync](../../../java/util/concurrent/CompletionStage.html#thenRunAsync-java.lang.Runnable-java.util.concurrent.Executor-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `action` \- the action to perform before completing the returned CompletionStage `executor` \- the executor to use for asynchronous execution Returns: the new CompletionStage * #### thenCombine public <U,V> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<V> thenCombine([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<? extends U> other, [BiFunction](../../../java/util/function/BiFunction.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),? super U,? extends V> fn) Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied function. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenCombine](../../../java/util/concurrent/CompletionStage.html#thenCombine-java.util.concurrent.CompletionStage-java.util.function.BiFunction-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the type of the other CompletionStage's result `V` \- the function's return type Parameters: `other` \- the other CompletionStage `fn` \- the function to use to compute the value of the returned CompletionStage Returns: the new CompletionStage * #### thenCombineAsync public <U,V> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<V> thenCombineAsync([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<? extends U> other, [BiFunction](../../../java/util/function/BiFunction.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),? super U,? extends V> fn) Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using this stage's default asynchronous execution facility, with the two results as arguments to the supplied function. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenCombineAsync](../../../java/util/concurrent/CompletionStage.html#thenCombineAsync-java.util.concurrent.CompletionStage-java.util.function.BiFunction-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the type of the other CompletionStage's result `V` \- the function's return type Parameters: `other` \- the other CompletionStage `fn` \- the function to use to compute the value of the returned CompletionStage Returns: the new CompletionStage * #### thenCombineAsync public <U,V> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<V> thenCombineAsync([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<? extends U> other, [BiFunction](../../../java/util/function/BiFunction.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),? super U,? extends V> fn, [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") executor) Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied function. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenCombineAsync](../../../java/util/concurrent/CompletionStage.html#thenCombineAsync-java.util.concurrent.CompletionStage-java.util.function.BiFunction-java.util.concurrent.Executor-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the type of the other CompletionStage's result `V` \- the function's return type Parameters: `other` \- the other CompletionStage `fn` \- the function to use to compute the value of the returned CompletionStage `executor` \- the executor to use for asynchronous execution Returns: the new CompletionStage * #### thenAcceptBoth public <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> thenAcceptBoth([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<? extends U> other, [BiConsumer](../../../java/util/function/BiConsumer.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),? super U> action) Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied action. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenAcceptBoth](../../../java/util/concurrent/CompletionStage.html#thenAcceptBoth-java.util.concurrent.CompletionStage-java.util.function.BiConsumer-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the type of the other CompletionStage's result Parameters: `other` \- the other CompletionStage `action` \- the action to perform before completing the returned CompletionStage Returns: the new CompletionStage * #### thenAcceptBothAsync public <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> thenAcceptBothAsync([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<? extends U> other, [BiConsumer](../../../java/util/function/BiConsumer.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),? super U> action) Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using this stage's default asynchronous execution facility, with the two results as arguments to the supplied action. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenAcceptBothAsync](../../../java/util/concurrent/CompletionStage.html#thenAcceptBothAsync-java.util.concurrent.CompletionStage-java.util.function.BiConsumer-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the type of the other CompletionStage's result Parameters: `other` \- the other CompletionStage `action` \- the action to perform before completing the returned CompletionStage Returns: the new CompletionStage * #### thenAcceptBothAsync public <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> thenAcceptBothAsync([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<? extends U> other, [BiConsumer](../../../java/util/function/BiConsumer.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),? super U> action, [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") executor) Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied action. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenAcceptBothAsync](../../../java/util/concurrent/CompletionStage.html#thenAcceptBothAsync-java.util.concurrent.CompletionStage-java.util.function.BiConsumer-java.util.concurrent.Executor-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the type of the other CompletionStage's result Parameters: `other` \- the other CompletionStage `action` \- the action to perform before completing the returned CompletionStage `executor` \- the executor to use for asynchronous execution Returns: the new CompletionStage * #### runAfterBoth public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> runAfterBoth([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<?> other, [Runnable](../../../java/lang/Runnable.html "interface in java.lang") action) Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[runAfterBoth](../../../java/util/concurrent/CompletionStage.html#runAfterBoth-java.util.concurrent.CompletionStage-java.lang.Runnable-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `other` \- the other CompletionStage `action` \- the action to perform before completing the returned CompletionStage Returns: the new CompletionStage * #### runAfterBothAsync public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> runAfterBothAsync([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<?> other, [Runnable](../../../java/lang/Runnable.html "interface in java.lang") action) Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action using this stage's default asynchronous execution facility. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[runAfterBothAsync](../../../java/util/concurrent/CompletionStage.html#runAfterBothAsync-java.util.concurrent.CompletionStage-java.lang.Runnable-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `other` \- the other CompletionStage `action` \- the action to perform before completing the returned CompletionStage Returns: the new CompletionStage * #### runAfterBothAsync public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> runAfterBothAsync([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<?> other, [Runnable](../../../java/lang/Runnable.html "interface in java.lang") action, [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") executor) Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action using the supplied executor. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[runAfterBothAsync](../../../java/util/concurrent/CompletionStage.html#runAfterBothAsync-java.util.concurrent.CompletionStage-java.lang.Runnable-java.util.concurrent.Executor-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `other` \- the other CompletionStage `action` \- the action to perform before completing the returned CompletionStage `executor` \- the executor to use for asynchronous execution Returns: the new CompletionStage * #### applyToEither public <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> applyToEither([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<? extends [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> other, [Function](../../../java/util/function/Function.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),U> fn) Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied function. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[applyToEither](../../../java/util/concurrent/CompletionStage.html#applyToEither-java.util.concurrent.CompletionStage-java.util.function.Function-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the function's return type Parameters: `other` \- the other CompletionStage `fn` \- the function to use to compute the value of the returned CompletionStage Returns: the new CompletionStage * #### applyToEitherAsync public <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> applyToEitherAsync([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<? extends [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> other, [Function](../../../java/util/function/Function.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),U> fn) Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using this stage's default asynchronous execution facility, with the corresponding result as argument to the supplied function. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[applyToEitherAsync](../../../java/util/concurrent/CompletionStage.html#applyToEitherAsync-java.util.concurrent.CompletionStage-java.util.function.Function-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the function's return type Parameters: `other` \- the other CompletionStage `fn` \- the function to use to compute the value of the returned CompletionStage Returns: the new CompletionStage * #### applyToEitherAsync public <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> applyToEitherAsync([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<? extends [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> other, [Function](../../../java/util/function/Function.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),U> fn, [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") executor) Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied function. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[applyToEitherAsync](../../../java/util/concurrent/CompletionStage.html#applyToEitherAsync-java.util.concurrent.CompletionStage-java.util.function.Function-java.util.concurrent.Executor-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the function's return type Parameters: `other` \- the other CompletionStage `fn` \- the function to use to compute the value of the returned CompletionStage `executor` \- the executor to use for asynchronous execution Returns: the new CompletionStage * #### acceptEither public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> acceptEither([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<? extends [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> other, [Consumer](../../../java/util/function/Consumer.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> action) Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied action. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[acceptEither](../../../java/util/concurrent/CompletionStage.html#acceptEither-java.util.concurrent.CompletionStage-java.util.function.Consumer-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `other` \- the other CompletionStage `action` \- the action to perform before completing the returned CompletionStage Returns: the new CompletionStage * #### acceptEitherAsync public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> acceptEitherAsync([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<? extends [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> other, [Consumer](../../../java/util/function/Consumer.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> action) Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using this stage's default asynchronous execution facility, with the corresponding result as argument to the supplied action. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[acceptEitherAsync](../../../java/util/concurrent/CompletionStage.html#acceptEitherAsync-java.util.concurrent.CompletionStage-java.util.function.Consumer-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `other` \- the other CompletionStage `action` \- the action to perform before completing the returned CompletionStage Returns: the new CompletionStage * #### acceptEitherAsync public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> acceptEitherAsync([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<? extends [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> other, [Consumer](../../../java/util/function/Consumer.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> action, [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") executor) Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied action. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[acceptEitherAsync](../../../java/util/concurrent/CompletionStage.html#acceptEitherAsync-java.util.concurrent.CompletionStage-java.util.function.Consumer-java.util.concurrent.Executor-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `other` \- the other CompletionStage `action` \- the action to perform before completing the returned CompletionStage `executor` \- the executor to use for asynchronous execution Returns: the new CompletionStage * #### runAfterEither public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> runAfterEither([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<?> other, [Runnable](../../../java/lang/Runnable.html "interface in java.lang") action) Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[runAfterEither](../../../java/util/concurrent/CompletionStage.html#runAfterEither-java.util.concurrent.CompletionStage-java.lang.Runnable-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `other` \- the other CompletionStage `action` \- the action to perform before completing the returned CompletionStage Returns: the new CompletionStage * #### runAfterEitherAsync public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> runAfterEitherAsync([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<?> other, [Runnable](../../../java/lang/Runnable.html "interface in java.lang") action) Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action using this stage's default asynchronous execution facility. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[runAfterEitherAsync](../../../java/util/concurrent/CompletionStage.html#runAfterEitherAsync-java.util.concurrent.CompletionStage-java.lang.Runnable-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `other` \- the other CompletionStage `action` \- the action to perform before completing the returned CompletionStage Returns: the new CompletionStage * #### runAfterEitherAsync public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> runAfterEitherAsync([CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<?> other, [Runnable](../../../java/lang/Runnable.html "interface in java.lang") action, [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") executor) Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action using the supplied executor. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[runAfterEitherAsync](../../../java/util/concurrent/CompletionStage.html#runAfterEitherAsync-java.util.concurrent.CompletionStage-java.lang.Runnable-java.util.concurrent.Executor-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `other` \- the other CompletionStage `action` \- the action to perform before completing the returned CompletionStage `executor` \- the executor to use for asynchronous execution Returns: the new CompletionStage * #### thenCompose public <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> thenCompose([Function](../../../java/util/function/Function.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),? extends [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<U>> fn) Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function. When this stage completes normally, the given function is invoked with this stage's result as the argument, returning another CompletionStage. When that stage completes normally, the CompletionStage returned by this method is completed with the same value. To ensure progress, the supplied function must arrange eventual completion of its result. This method is analogous to[Optional.flatMap](../../../java/util/Optional.html#flatMap-java.util.function.Function-) and[Stream.flatMap](../../../java/util/stream/Stream.html#flatMap-java.util.function.Function-). See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenCompose](../../../java/util/concurrent/CompletionStage.html#thenCompose-java.util.function.Function-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the type of the returned CompletionStage's result Parameters: `fn` \- the function to use to compute another CompletionStage Returns: the new CompletionStage * #### thenComposeAsync public <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> thenComposeAsync([Function](../../../java/util/function/Function.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),? extends [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<U>> fn) Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function, executed using this stage's default asynchronous execution facility. When this stage completes normally, the given function is invoked with this stage's result as the argument, returning another CompletionStage. When that stage completes normally, the CompletionStage returned by this method is completed with the same value. To ensure progress, the supplied function must arrange eventual completion of its result. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenComposeAsync](../../../java/util/concurrent/CompletionStage.html#thenComposeAsync-java.util.function.Function-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the type of the returned CompletionStage's result Parameters: `fn` \- the function to use to compute another CompletionStage Returns: the new CompletionStage * #### thenComposeAsync public <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> thenComposeAsync([Function](../../../java/util/function/Function.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),? extends [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<U>> fn, [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") executor) Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function, executed using the supplied Executor. When this stage completes normally, the given function is invoked with this stage's result as the argument, returning another CompletionStage. When that stage completes normally, the CompletionStage returned by this method is completed with the same value. To ensure progress, the supplied function must arrange eventual completion of its result. See the [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent") documentation for rules covering exceptional completion. Specified by: `[thenComposeAsync](../../../java/util/concurrent/CompletionStage.html#thenComposeAsync-java.util.function.Function-java.util.concurrent.Executor-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the type of the returned CompletionStage's result Parameters: `fn` \- the function to use to compute another CompletionStage `executor` \- the executor to use for asynchronous execution Returns: the new CompletionStage * #### whenComplete public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> whenComplete([BiConsumer](../../../java/util/function/BiConsumer.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),? super [Throwable](../../../java/lang/Throwable.html "class in java.lang")> action) Returns a new CompletionStage with the same result or exception as this stage, that executes the given action when this stage completes. When this stage is complete, the given action is invoked with the result (or `null` if none) and the exception (or`null` if none) of this stage as arguments. The returned stage is completed when the action returns. Unlike method [handle](../../../java/util/concurrent/CompletionStage.html#handle-java.util.function.BiFunction-), this method is not designed to translate completion outcomes, so the supplied action should not throw an exception. However, if it does, the following rules apply: if this stage completed normally but the supplied action throws an exception, then the returned stage completes exceptionally with the supplied action's exception. Or, if this stage completed exceptionally and the supplied action throws an exception, then the returned stage completes exceptionally with this stage's exception. Specified by: `[whenComplete](../../../java/util/concurrent/CompletionStage.html#whenComplete-java.util.function.BiConsumer-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `action` \- the action to perform Returns: the new CompletionStage * #### whenCompleteAsync public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> whenCompleteAsync([BiConsumer](../../../java/util/function/BiConsumer.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),? super [Throwable](../../../java/lang/Throwable.html "class in java.lang")> action) Returns a new CompletionStage with the same result or exception as this stage, that executes the given action using this stage's default asynchronous execution facility when this stage completes. When this stage is complete, the given action is invoked with the result (or `null` if none) and the exception (or `null` if none) of this stage as arguments. The returned stage is completed when the action returns. Unlike method [handleAsync](../../../java/util/concurrent/CompletionStage.html#handleAsync-java.util.function.BiFunction-), this method is not designed to translate completion outcomes, so the supplied action should not throw an exception. However, if it does, the following rules apply: If this stage completed normally but the supplied action throws an exception, then the returned stage completes exceptionally with the supplied action's exception. Or, if this stage completed exceptionally and the supplied action throws an exception, then the returned stage completes exceptionally with this stage's exception. Specified by: `[whenCompleteAsync](../../../java/util/concurrent/CompletionStage.html#whenCompleteAsync-java.util.function.BiConsumer-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `action` \- the action to perform Returns: the new CompletionStage * #### whenCompleteAsync public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> whenCompleteAsync([BiConsumer](../../../java/util/function/BiConsumer.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),? super [Throwable](../../../java/lang/Throwable.html "class in java.lang")> action, [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") executor) Returns a new CompletionStage with the same result or exception as this stage, that executes the given action using the supplied Executor when this stage completes. When this stage is complete, the given action is invoked with the result (or `null` if none) and the exception (or `null` if none) of this stage as arguments. The returned stage is completed when the action returns. Unlike method [handleAsync](../../../java/util/concurrent/CompletionStage.html#handleAsync-java.util.function.BiFunction-java.util.concurrent.Executor-), this method is not designed to translate completion outcomes, so the supplied action should not throw an exception. However, if it does, the following rules apply: If this stage completed normally but the supplied action throws an exception, then the returned stage completes exceptionally with the supplied action's exception. Or, if this stage completed exceptionally and the supplied action throws an exception, then the returned stage completes exceptionally with this stage's exception. Specified by: `[whenCompleteAsync](../../../java/util/concurrent/CompletionStage.html#whenCompleteAsync-java.util.function.BiConsumer-java.util.concurrent.Executor-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `action` \- the action to perform `executor` \- the executor to use for asynchronous execution Returns: the new CompletionStage * #### handle public <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> handle([BiFunction](../../../java/util/function/BiFunction.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),[Throwable](../../../java/lang/Throwable.html "class in java.lang"),? extends U> fn) Returns a new CompletionStage that, when this stage completes either normally or exceptionally, is executed with this stage's result and exception as arguments to the supplied function. When this stage is complete, the given function is invoked with the result (or `null` if none) and the exception (or`null` if none) of this stage as arguments, and the function's result is used to complete the returned stage. Specified by: `[handle](../../../java/util/concurrent/CompletionStage.html#handle-java.util.function.BiFunction-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the function's return type Parameters: `fn` \- the function to use to compute the value of the returned CompletionStage Returns: the new CompletionStage * #### handleAsync public <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> handleAsync([BiFunction](../../../java/util/function/BiFunction.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),[Throwable](../../../java/lang/Throwable.html "class in java.lang"),? extends U> fn) Returns a new CompletionStage that, when this stage completes either normally or exceptionally, is executed using this stage's default asynchronous execution facility, with this stage's result and exception as arguments to the supplied function. When this stage is complete, the given function is invoked with the result (or `null` if none) and the exception (or`null` if none) of this stage as arguments, and the function's result is used to complete the returned stage. Specified by: `[handleAsync](../../../java/util/concurrent/CompletionStage.html#handleAsync-java.util.function.BiFunction-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the function's return type Parameters: `fn` \- the function to use to compute the value of the returned CompletionStage Returns: the new CompletionStage * #### handleAsync public <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> handleAsync([BiFunction](../../../java/util/function/BiFunction.html "interface in java.util.function")<? super [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture"),[Throwable](../../../java/lang/Throwable.html "class in java.lang"),? extends U> fn, [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") executor) Returns a new CompletionStage that, when this stage completes either normally or exceptionally, is executed using the supplied executor, with this stage's result and exception as arguments to the supplied function. When this stage is complete, the given function is invoked with the result (or `null` if none) and the exception (or`null` if none) of this stage as arguments, and the function's result is used to complete the returned stage. Specified by: `[handleAsync](../../../java/util/concurrent/CompletionStage.html#handleAsync-java.util.function.BiFunction-java.util.concurrent.Executor-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Type Parameters: `U` \- the function's return type Parameters: `fn` \- the function to use to compute the value of the returned CompletionStage `executor` \- the executor to use for asynchronous execution Returns: the new CompletionStage * #### toCompletableFuture public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> toCompletableFuture() Returns this CompletableFuture. Specified by: `[toCompletableFuture](../../../java/util/concurrent/CompletionStage.html#toCompletableFuture--)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Returns: this CompletableFuture * #### exceptionally public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> exceptionally([Function](../../../java/util/function/Function.html "interface in java.util.function")<[Throwable](../../../java/lang/Throwable.html "class in java.lang"),? extends [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> fn) Returns a new CompletableFuture that is completed when this CompletableFuture completes, with the result of the given function of the exception triggering this CompletableFuture's completion when it completes exceptionally; otherwise, if this CompletableFuture completes normally, then the returned CompletableFuture also completes normally with the same value. Note: More flexible versions of this functionality are available using methods `whenComplete` and `handle`. Specified by: `[exceptionally](../../../java/util/concurrent/CompletionStage.html#exceptionally-java.util.function.Function-)` in interface `[CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `fn` \- the function to use to compute the value of the returned CompletableFuture if this CompletableFuture completed exceptionally Returns: the new CompletableFuture * #### allOf public static [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Void](../../../java/lang/Void.html "class in java.lang")> allOf([CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<?>... cfs) Returns a new CompletableFuture that is completed when all of the given CompletableFutures complete. If any of the given CompletableFutures complete exceptionally, then the returned CompletableFuture also does so, with a CompletionException holding this exception as its cause. Otherwise, the results, if any, of the given CompletableFutures are not reflected in the returned CompletableFuture, but may be obtained by inspecting them individually. If no CompletableFutures are provided, returns a CompletableFuture completed with the value`null`. Among the applications of this method is to await completion of a set of independent CompletableFutures before continuing a program, as in: `CompletableFuture.allOf(c1, c2, c3).join();`. Parameters: `cfs` \- the CompletableFutures Returns: a new CompletableFuture that is completed when all of the given CompletableFutures complete Throws: `[NullPointerException](../../../java/lang/NullPointerException.html "class in java.lang")` \- if the array or any of its elements are`null` * #### anyOf public static [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[Object](../../../java/lang/Object.html "class in java.lang")> anyOf([CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<?>... cfs) Returns a new CompletableFuture that is completed when any of the given CompletableFutures complete, with the same result. Otherwise, if it completed exceptionally, the returned CompletableFuture also does so, with a CompletionException holding this exception as its cause. If no CompletableFutures are provided, returns an incomplete CompletableFuture. Parameters: `cfs` \- the CompletableFutures Returns: a new CompletableFuture that is completed with the result or exception of any of the given CompletableFutures when one completes Throws: `[NullPointerException](../../../java/lang/NullPointerException.html "class in java.lang")` \- if the array or any of its elements are`null` * #### cancel public boolean cancel(boolean mayInterruptIfRunning) If not already completed, completes this CompletableFuture with a [CancellationException](../../../java/util/concurrent/CancellationException.html "class in java.util.concurrent"). Dependent CompletableFutures that have not already completed will also complete exceptionally, with a [CompletionException](../../../java/util/concurrent/CompletionException.html "class in java.util.concurrent") caused by this `CancellationException`. Specified by: `[cancel](../../../java/util/concurrent/Future.html#cancel-boolean-)` in interface `[Future](../../../java/util/concurrent/Future.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Parameters: `mayInterruptIfRunning` \- this value has no effect in this implementation because interrupts are not used to control processing. Returns: `true` if this task is now cancelled * #### isCancelled public boolean isCancelled() Returns `true` if this CompletableFuture was cancelled before it completed normally. Specified by: `[isCancelled](../../../java/util/concurrent/Future.html#isCancelled--)` in interface `[Future](../../../java/util/concurrent/Future.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")>` Returns: `true` if this CompletableFuture was cancelled before it completed normally * #### isCompletedExceptionally public boolean isCompletedExceptionally() Returns `true` if this CompletableFuture completed exceptionally, in any way. Possible causes include cancellation, explicit invocation of ` completeExceptionally`, and abrupt termination of a CompletionStage action. Returns: `true` if this CompletableFuture completed exceptionally * #### obtrudeValue public void obtrudeValue([T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture") value) Forcibly sets or resets the value subsequently returned by method [get()](../../../java/util/concurrent/CompletableFuture.html#get--) and related methods, whether or not already completed. This method is designed for use only in error recovery actions, and even in such situations may result in ongoing dependent completions using established versus overwritten outcomes. Parameters: `value` \- the completion value * #### obtrudeException public void obtrudeException([Throwable](../../../java/lang/Throwable.html "class in java.lang") ex) Forcibly causes subsequent invocations of method [get()](../../../java/util/concurrent/CompletableFuture.html#get--) and related methods to throw the given exception, whether or not already completed. This method is designed for use only in error recovery actions, and even in such situations may result in ongoing dependent completions using established versus overwritten outcomes. Parameters: `ex` \- the exception Throws: `[NullPointerException](../../../java/lang/NullPointerException.html "class in java.lang")` \- if the exception is null * #### getNumberOfDependents public int getNumberOfDependents() Returns the estimated number of CompletableFutures whose completions are awaiting completion of this CompletableFuture. This method is designed for use in monitoring system state, not for synchronization control. Returns: the number of dependent CompletableFutures * #### toString public [String](../../../java/lang/String.html "class in java.lang") toString() Returns a string identifying this CompletableFuture, as well as its completion state. The state, in brackets, contains the String `"Completed Normally"` or the String ` "Completed Exceptionally"`, or the String `"Not completed"` followed by the number of CompletableFutures dependent upon its completion, if any. Overrides: `[toString](../../../java/lang/Object.html#toString--)` in class `[Object](../../../java/lang/Object.html "class in java.lang")` Returns: a string identifying this CompletableFuture, as well as its state * #### newIncompleteFuture public <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> newIncompleteFuture() Returns a new incomplete CompletableFuture of the type to be returned by a CompletionStage method. Subclasses should normally override this method to return an instance of the same class as this CompletableFuture. The default implementation returns an instance of class CompletableFuture. Type Parameters: `U` \- the type of the value Returns: a new CompletableFuture Since: 9 * #### defaultExecutor public [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") defaultExecutor() Returns the default Executor used for async methods that do not specify an Executor. This class uses the [ForkJoinPool.commonPool()](../../../java/util/concurrent/ForkJoinPool.html#commonPool--) if it supports more than one parallel thread, or else an Executor using one thread per async task. This method may be overridden in subclasses to return an Executor that provides at least one independent thread. Returns: the executor Since: 9 * #### copy public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> copy() Returns a new CompletableFuture that is completed normally with the same value as this CompletableFuture when it completes normally. If this CompletableFuture completes exceptionally, then the returned CompletableFuture completes exceptionally with a CompletionException with this exception as cause. The behavior is equivalent to `thenApply(x -> x)`. This method may be useful as a form of "defensive copying", to prevent clients from completing, while still being able to arrange dependent actions. Returns: the new CompletableFuture Since: 9 * #### minimalCompletionStage public [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> minimalCompletionStage() Returns a new CompletionStage that is completed normally with the same value as this CompletableFuture when it completes normally, and cannot be independently completed or otherwise used in ways not defined by the methods of interface [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent"). If this CompletableFuture completes exceptionally, then the returned CompletionStage completes exceptionally with a CompletionException with this exception as cause. Unless overridden by a subclass, a new non-minimal CompletableFuture with all methods available can be obtained from a minimal CompletionStage via [toCompletableFuture()](../../../java/util/concurrent/CompletableFuture.html#toCompletableFuture--). For example, completion of a minimal stage can be awaited by `minimalStage.toCompletableFuture().join(); ` Returns: the new CompletionStage Since: 9 * #### completeAsync public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> completeAsync([Supplier](../../../java/util/function/Supplier.html "interface in java.util.function")<? extends [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> supplier, [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") executor) Completes this CompletableFuture with the result of the given Supplier function invoked from an asynchronous task using the given executor. Parameters: `supplier` \- a function returning the value to be used to complete this CompletableFuture `executor` \- the executor to use for asynchronous execution Returns: this CompletableFuture Since: 9 * #### completeAsync public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> completeAsync([Supplier](../../../java/util/function/Supplier.html "interface in java.util.function")<? extends [T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> supplier) Completes this CompletableFuture with the result of the given Supplier function invoked from an asynchronous task using the default executor. Parameters: `supplier` \- a function returning the value to be used to complete this CompletableFuture Returns: this CompletableFuture Since: 9 * #### orTimeout public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> orTimeout(long timeout, [TimeUnit](../../../java/util/concurrent/TimeUnit.html "enum in java.util.concurrent") unit) Exceptionally completes this CompletableFuture with a [TimeoutException](../../../java/util/concurrent/TimeoutException.html "class in java.util.concurrent") if not otherwise completed before the given timeout. Parameters: `timeout` \- how long to wait before completing exceptionally with a TimeoutException, in units of `unit` `unit` \- a `TimeUnit` determining how to interpret the`timeout` parameter Returns: this CompletableFuture Since: 9 * #### completeOnTimeout public [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<[T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture")> completeOnTimeout([T](../../../java/util/concurrent/CompletableFuture.html "type parameter in CompletableFuture") value, long timeout, [TimeUnit](../../../java/util/concurrent/TimeUnit.html "enum in java.util.concurrent") unit) Completes this CompletableFuture with the given value if not otherwise completed before the given timeout. Parameters: `value` \- the value to use upon timeout `timeout` \- how long to wait before completing normally with the given value, in units of `unit` `unit` \- a `TimeUnit` determining how to interpret the`timeout` parameter Returns: this CompletableFuture Since: 9 * #### delayedExecutor public static [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") delayedExecutor(long delay, [TimeUnit](../../../java/util/concurrent/TimeUnit.html "enum in java.util.concurrent") unit, [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") executor) Returns a new Executor that submits a task to the given base executor after the given delay (or no delay if non-positive). Each delay commences upon invocation of the returned executor's`execute` method. Parameters: `delay` \- how long to delay, in units of `unit` `unit` \- a `TimeUnit` determining how to interpret the`delay` parameter `executor` \- the base executor Returns: the new delayed executor Since: 9 * #### delayedExecutor public static [Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") delayedExecutor(long delay, [TimeUnit](../../../java/util/concurrent/TimeUnit.html "enum in java.util.concurrent") unit) Returns a new Executor that submits a task to the default executor after the given delay (or no delay if non-positive). Each delay commences upon invocation of the returned executor's`execute` method. Parameters: `delay` \- how long to delay, in units of `unit` `unit` \- a `TimeUnit` determining how to interpret the`delay` parameter Returns: the new delayed executor Since: 9 * #### completedStage public static <U> [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<U> completedStage(U value) Returns a new CompletionStage that is already completed with the given value and supports only those methods in interface [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent"). Type Parameters: `U` \- the type of the value Parameters: `value` \- the value Returns: the completed CompletionStage Since: 9 * #### failedFuture public static <U> [CompletableFuture](../../../java/util/concurrent/CompletableFuture.html "class in java.util.concurrent")<U> failedFuture([Throwable](../../../java/lang/Throwable.html "class in java.lang") ex) Returns a new CompletableFuture that is already completed exceptionally with the given exception. Type Parameters: `U` \- the type of the value Parameters: `ex` \- the exception Returns: the exceptionally completed CompletableFuture Since: 9 * #### failedStage public static <U> [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent")<U> failedStage([Throwable](../../../java/lang/Throwable.html "class in java.lang") ex) Returns a new CompletionStage that is already completed exceptionally with the given exception and supports only those methods in interface [CompletionStage](../../../java/util/concurrent/CompletionStage.html "interface in java.util.concurrent"). Type Parameters: `U` \- the type of the value Parameters: `ex` \- the exception Returns: the exceptionally completed CompletionStage Since: 9