不爱学习的墨镜 · 【中国焦点面对面】从北京中轴线,读懂中华文明 ...· 2 月前 · |
飞奔的莲藕 · js如何引用json文件路径 | ...· 2 月前 · |
寂寞的芹菜 · Power BI 微课堂 | ...· 2 月前 · |
高大的小摩托 · Kindle退出中国市场,国产电子书阅读器机 ...· 3 月前 · |
成熟的充电器 · 编解码SHA256WITHECDSA - ...· 7 月前 · |
Future
that may be explicitly completed (setting its
value and status), and may be used as a
CompletionStage
,
supporting dependent functions and actions that trigger upon its
completion.
When two or more threads attempt to
complete
,
completeExceptionally
, or
cancel
a CompletableFuture, only one of them succeeds.
In addition to these and related methods for directly
manipulating status and results, CompletableFuture implements
interface
CompletionStage
with the following policies:
ForkJoinPool.commonPool()
(unless it does not support a parallelism level of at least two, in
which case, a new Thread is created to run each task). To simplify
monitoring, debugging, and tracking, all generated asynchronous
tasks are instances of the marker interface
CompletableFuture.AsynchronousCompletionTask
.
CompletableFuture also implements
Future
with the following
policies:
FutureTask
) this class has no direct
control over the computation that causes it to be completed,
cancellation is treated as just another form of exceptional
completion. Method
cancel
has the same effect as
completeExceptionally(new CancellationException())
. Method
isCompletedExceptionally()
can be used to determine if a
CompletableFuture completed in any exceptional fashion.
get()
and
get(long, TimeUnit)
throw an
ExecutionException
with the same cause as held in the
corresponding CompletionException. To simplify usage in most
contexts, this class also defines methods
join()
and
getNow(T)
that instead throw the CompletionException directly
in these cases.
static interface
CompletableFuture.AsynchronousCompletionTask
async
methods.
CompletableFuture
<
Void
>
acceptEither
(
CompletionStage
<? extends
T
> other,
Consumer
<? super
T
> action)
CompletableFuture
<
Void
>
acceptEitherAsync
(
CompletionStage
<? extends
T
> other,
Consumer
<? super
T
> action)
CompletableFuture
<
Void
>
acceptEitherAsync
(
CompletionStage
<? extends
T
> other,
Consumer
<? super
T
> action,
Executor
executor)
static
CompletableFuture
<
Void
>
allOf
(
CompletableFuture
<?>... cfs)
static
CompletableFuture
<
Object
>
anyOf
(
CompletableFuture
<?>... cfs)
<U>
CompletableFuture
<U>
applyToEither
(
CompletionStage
<? extends
T
> other,
Function
<? super
T
,U> fn)
<U>
CompletableFuture
<U>
applyToEitherAsync
(
CompletionStage
<? extends
T
> other,
Function
<? super
T
,U> fn)
<U>
CompletableFuture
<U>
applyToEitherAsync
(
CompletionStage
<? extends
T
> other,
Function
<? super
T
,U> fn,
Executor
executor)
boolean
cancel
(boolean mayInterruptIfRunning)
CancellationException
.
boolean
complete
(
T
value)
get()
and related methods to the given value.
static <U>
CompletableFuture
<U>
completedFuture
(U value)
boolean
completeExceptionally
(
Throwable
ex)
get()
and related methods to throw the given exception.
CompletableFuture
<
T
>
exceptionally
(
Function
<
Throwable
,? extends
T
> fn)
get
()
get
(long timeout,
TimeUnit
unit)
getNow
(
T
valueIfAbsent)
getNumberOfDependents
()
<U>
CompletableFuture
<U>
handle
(
BiFunction
<? super
T
,
Throwable
,? extends U> fn)
<U>
CompletableFuture
<U>
handleAsync
(
BiFunction
<? super
T
,
Throwable
,? extends U> fn)
<U>
CompletableFuture
<U>
handleAsync
(
BiFunction
<? super
T
,
Throwable
,? extends U> fn,
Executor
executor)
boolean
isCancelled
()
true
if this CompletableFuture was cancelled
before it completed normally.
boolean
isCompletedExceptionally
()
true
if this CompletableFuture completed
exceptionally, in any way.
boolean
isDone
()
true
if completed in any fashion: normally,
exceptionally, or via cancellation.
join
()
obtrudeException
(
Throwable
ex)
get()
and related methods to throw the given exception, whether or
not already completed.
obtrudeValue
(
T
value)
get()
and related methods, whether or not
already completed.
CompletableFuture
<
Void
>
runAfterBoth
(
CompletionStage
<?> other,
Runnable
action)
CompletableFuture
<
Void
>
runAfterBothAsync
(
CompletionStage
<?> other,
Runnable
action)
CompletableFuture
<
Void
>
runAfterBothAsync
(
CompletionStage
<?> other,
Runnable
action,
Executor
executor)
CompletableFuture
<
Void
>
runAfterEither
(
CompletionStage
<?> other,
Runnable
action)
CompletableFuture
<
Void
>
runAfterEitherAsync
(
CompletionStage
<?> other,
Runnable
action)
CompletableFuture
<
Void
>
runAfterEitherAsync
(
CompletionStage
<?> other,
Runnable
action,
Executor
executor)
static
CompletableFuture
<
Void
>
runAsync
(
Runnable
runnable)
ForkJoinPool.commonPool()
after
it runs the given action.
static
CompletableFuture
<
Void
>
runAsync
(
Runnable
runnable,
Executor
executor)
static <U>
CompletableFuture
<U>
supplyAsync
(
Supplier
<U> supplier)
ForkJoinPool.commonPool()
with
the value obtained by calling the given Supplier.
static <U>
CompletableFuture
<U>
supplyAsync
(
Supplier
<U> supplier,
Executor
executor)
CompletableFuture
<
Void
>
thenAccept
(
Consumer
<? super
T
> action)
CompletableFuture
<
Void
>
thenAcceptAsync
(
Consumer
<? super
T
> action)
CompletableFuture
<
Void
>
thenAcceptAsync
(
Consumer
<? super
T
> action,
Executor
executor)
<U>
CompletableFuture
<
Void
>
thenAcceptBoth
(
CompletionStage
<? extends U> other,
BiConsumer
<? super
T
,? super U> action)
<U>
CompletableFuture
<
Void
>
thenAcceptBothAsync
(
CompletionStage
<? extends U> other,
BiConsumer
<? super
T
,? super U> action)
<U>
CompletableFuture
<
Void
>
thenAcceptBothAsync
(
CompletionStage
<? extends U> other,
BiConsumer
<? super
T
,? super U> action,
Executor
executor)
<U>
CompletableFuture
<U>
thenApply
(
Function
<? super
T
,? extends U> fn)
<U>
CompletableFuture
<U>
thenApplyAsync
(
Function
<? super
T
,? extends U> fn)
<U>
CompletableFuture
<U>
thenApplyAsync
(
Function
<? super
T
,? extends U> fn,
Executor
executor)
<U,V>
CompletableFuture
<V>
thenCombine
(
CompletionStage
<? extends U> other,
BiFunction
<? super
T
,? super U,? extends V> fn)
<U,V>
CompletableFuture
<V>
thenCombineAsync
(
CompletionStage
<? extends U> other,
BiFunction
<? super
T
,? super U,? extends V> fn)
<U,V>
CompletableFuture
<V>
thenCombineAsync
(
CompletionStage
<? extends U> other,
BiFunction
<? super
T
,? super U,? extends V> fn,
Executor
executor)
<U>
CompletableFuture
<U>
thenCompose
(
Function
<? super
T
,? extends
CompletionStage
<U>> fn)
<U>
CompletableFuture
<U>
thenComposeAsync
(
Function
<? super
T
,? extends
CompletionStage
<U>> fn)
<U>
CompletableFuture
<U>
thenComposeAsync
(
Function
<? super
T
,? extends
CompletionStage
<U>> fn,
Executor
executor)
CompletableFuture
<
Void
>
thenRun
(
Runnable
action)
CompletableFuture
<
Void
>
thenRunAsync
(
Runnable
action)
CompletableFuture
<
Void
>
thenRunAsync
(
Runnable
action,
Executor
executor)
CompletableFuture
<
T
>
toCompletableFuture
()
String
toString
()
CompletableFuture
<
T
>
whenComplete
(
BiConsumer
<? super
T
,? super
Throwable
> action)
CompletableFuture
<
T
>
whenCompleteAsync
(
BiConsumer
<? super
T
,? super
Throwable
> action)
CompletableFuture
<
T
>
whenCompleteAsync
(
BiConsumer
<? super
T
,? super
Throwable
> action,
Executor
executor)
public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier)
ForkJoinPool.commonPool()
with
the value obtained by calling the given Supplier.
U
- the function's return type
supplier
- a function returning the value to be used
to complete the returned CompletableFuture
public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier, Executor executor)
U
- the function's return type
supplier
- a function returning the value to be used
to complete the returned CompletableFuture
executor
- the executor to use for asynchronous execution
public static CompletableFuture<Void> runAsync(Runnable runnable)
ForkJoinPool.commonPool()
after
it runs the given action.
runnable
- the action to run before completing the
returned CompletableFuture
public static CompletableFuture<Void> runAsync(Runnable runnable, Executor executor)
runnable
- the action to run before completing the
returned CompletableFuture
executor
- the executor to use for asynchronous execution
public static <U> CompletableFuture<U> completedFuture(U value)
U
- the type of the value
value
- the value
public boolean isDone()
true
if completed in any fashion: normally,
exceptionally, or via cancellation.
isDone
in interface
Future
<
T
>
true
if completed
get
in interface
Future
<
T
>
CancellationException
- if this future was cancelled
ExecutionException
- if this future completed exceptionally
InterruptedException
- if the current thread was interrupted
while waiting
get
in interface
Future
<
T
>
timeout
- the maximum time to wait
unit
- the time unit of the timeout argument
CancellationException
- if this future was cancelled
ExecutionException
- if this future completed exceptionally
InterruptedException
- if the current thread was interrupted
while waiting
TimeoutException
- if the wait timed out
public T join()
CompletionException
with the underlying
exception as its cause.
CancellationException
- if the computation was cancelled
CompletionException
- if this future completed
exceptionally or a completion computation threw an exception
public T getNow(T valueIfAbsent)
valueIfAbsent
- the value to return if not completed
CancellationException
- if the computation was cancelled
CompletionException
- if this future completed
exceptionally or a completion computation threw an exception
public boolean complete(T value)
get()
and related methods to the given value.
value
- the result value
true
if this invocation caused this CompletableFuture
to transition to a completed state, else
false
public boolean completeExceptionally(Throwable ex)
get()
and related methods to throw the given exception.
ex
- the exception
true
if this invocation caused this CompletableFuture
to transition to a completed state, else
false
public <U> CompletableFuture<U> thenApply(Function<? super T,? extends U> fn)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
thenApply
in interface
CompletionStage
<
T
>
U
- the function's return type
fn
- the function to use to compute the value of
the returned CompletionStage
public <U> CompletableFuture<U> thenApplyAsync(Function<? super T,? extends U> fn)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
thenApplyAsync
in interface
CompletionStage
<
T
>
U
- the function's return type
fn
- the function to use to compute the value of
the returned CompletionStage
public <U> CompletableFuture<U> thenApplyAsync(Function<? super T,? extends U> fn, Executor executor)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
thenApplyAsync
in interface
CompletionStage
<
T
>
U
- the function's return type
fn
- the function to use to compute the value of
the returned CompletionStage
executor
- the executor to use for asynchronous execution
public CompletableFuture<Void> thenAccept(Consumer<? super T> action)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
thenAccept
in interface
CompletionStage
<
T
>
action
- the action to perform before completing the
returned CompletionStage
public CompletableFuture<Void> thenAcceptAsync(Consumer<? super T> action)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
thenAcceptAsync
in interface
CompletionStage
<
T
>
action
- the action to perform before completing the
returned CompletionStage
public CompletableFuture<Void> thenAcceptAsync(Consumer<? super T> action, Executor executor)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
thenAcceptAsync
in interface
CompletionStage
<
T
>
action
- the action to perform before completing the
returned CompletionStage
executor
- the executor to use for asynchronous execution
public CompletableFuture<Void> thenRun(Runnable action)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
thenRun
in interface
CompletionStage
<
T
>
action
- the action to perform before completing the
returned CompletionStage
public CompletableFuture<Void> thenRunAsync(Runnable action)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
thenRunAsync
in interface
CompletionStage
<
T
>
action
- the action to perform before completing the
returned CompletionStage
public CompletableFuture<Void> thenRunAsync(Runnable action, Executor executor)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
thenRunAsync
in interface
CompletionStage
<
T
>
action
- the action to perform before completing the
returned CompletionStage
executor
- the executor to use for asynchronous execution
public <U,V> CompletableFuture<V> thenCombine(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
thenCombine
in interface
CompletionStage
<
T
>
U
- the type of the other CompletionStage's result
V
- the function's return type
other
- the other CompletionStage
fn
- the function to use to compute the value of
the returned CompletionStage
public <U,V> CompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
thenCombineAsync
in interface
CompletionStage
<
T
>
U
- the type of the other CompletionStage's result
V
- the function's return type
other
- the other CompletionStage
fn
- the function to use to compute the value of
the returned CompletionStage
public <U,V> CompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn, Executor executor)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
thenCombineAsync
in interface
CompletionStage
<
T
>
U
- the type of the other CompletionStage's result
V
- the function's return type
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
public <U> CompletableFuture<Void> thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
thenAcceptBoth
in interface
CompletionStage
<
T
>
U
- the type of the other CompletionStage's result
other
- the other CompletionStage
action
- the action to perform before completing the
returned CompletionStage
public <U> CompletableFuture<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action)
CompletionStage
thenAcceptBothAsync
in interface
CompletionStage
<
T
>
U
- the type of the other CompletionStage's result
other
- the other CompletionStage
action
- the action to perform before completing the
returned CompletionStage
public <U> CompletableFuture<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action, Executor executor)
CompletionStage
thenAcceptBothAsync
in interface
CompletionStage
<
T
>
U
- the type of the other CompletionStage's result
other
- the other CompletionStage
action
- the action to perform before completing the
returned CompletionStage
executor
- the executor to use for asynchronous execution
public CompletableFuture<Void> runAfterBoth(CompletionStage<?> other, Runnable action)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
runAfterBoth
in interface
CompletionStage
<
T
>
other
- the other CompletionStage
action
- the action to perform before completing the
returned CompletionStage
public CompletableFuture<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
runAfterBothAsync
in interface
CompletionStage
<
T
>
other
- the other CompletionStage
action
- the action to perform before completing the
returned CompletionStage
public CompletableFuture<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
runAfterBothAsync
in interface
CompletionStage
<
T
>
other
- the other CompletionStage
action
- the action to perform before completing the
returned CompletionStage
executor
- the executor to use for asynchronous execution
public <U> CompletableFuture<U> applyToEither(CompletionStage<? extends T> other, Function<? super T,U> fn)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
applyToEither
in interface
CompletionStage
<
T
>
U
- the function's return type
other
- the other CompletionStage
fn
- the function to use to compute the value of
the returned CompletionStage
public <U> CompletableFuture<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T,U> fn)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
applyToEitherAsync
in interface
CompletionStage
<
T
>
U
- the function's return type
other
- the other CompletionStage
fn
- the function to use to compute the value of
the returned CompletionStage
public <U> CompletableFuture<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T,U> fn, Executor executor)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
applyToEitherAsync
in interface
CompletionStage
<
T
>
U
- the function's return type
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
public CompletableFuture<Void> acceptEither(CompletionStage<? extends T> other, Consumer<? super T> action)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
acceptEither
in interface
CompletionStage
<
T
>
other
- the other CompletionStage
action
- the action to perform before completing the
returned CompletionStage
public CompletableFuture<Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
acceptEitherAsync
in interface
CompletionStage
<
T
>
other
- the other CompletionStage
action
- the action to perform before completing the
returned CompletionStage
public CompletableFuture<Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
acceptEitherAsync
in interface
CompletionStage
<
T
>
other
- the other CompletionStage
action
- the action to perform before completing the
returned CompletionStage
executor
- the executor to use for asynchronous execution
public CompletableFuture<Void> runAfterEither(CompletionStage<?> other, Runnable action)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
runAfterEither
in interface
CompletionStage
<
T
>
other
- the other CompletionStage
action
- the action to perform before completing the
returned CompletionStage
public CompletableFuture<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
runAfterEitherAsync
in interface
CompletionStage
<
T
>
other
- the other CompletionStage
action
- the action to perform before completing the
returned CompletionStage
public CompletableFuture<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
runAfterEitherAsync
in interface
CompletionStage
<
T
>
other
- the other CompletionStage
action
- the action to perform before completing the
returned CompletionStage
executor
- the executor to use for asynchronous execution
public <U> CompletableFuture<U> thenCompose(Function<? super T,? extends CompletionStage<U>> fn)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
thenCompose
in interface
CompletionStage
<
T
>
U
- the type of the returned CompletionStage's result
fn
- the function returning a new CompletionStage
public <U> CompletableFuture<U> thenComposeAsync(Function<? super T,? extends CompletionStage<U>> fn)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
thenComposeAsync
in interface
CompletionStage
<
T
>
U
- the type of the returned CompletionStage's result
fn
- the function returning a new CompletionStage
public <U> CompletableFuture<U> thenComposeAsync(Function<? super T,? extends CompletionStage<U>> fn, Executor executor)
CompletionStage
CompletionStage
documentation for rules
covering exceptional completion.
thenComposeAsync
in interface
CompletionStage
<
T
>
U
- the type of the returned CompletionStage's result
fn
- the function returning a new CompletionStage
executor
- the executor to use for asynchronous execution
public CompletableFuture<T> whenComplete(BiConsumer<? super T,? super Throwable> action)
CompletionStage
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. If the supplied action itself encounters an
exception, then the returned stage exceptionally completes with this
exception unless this stage also completed exceptionally.
whenComplete
in interface
CompletionStage
<
T
>
action
- the action to perform
public CompletableFuture<T> whenCompleteAsync(BiConsumer<? super T,? super Throwable> action)
CompletionStage
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. If the supplied action itself encounters an
exception, then the returned stage exceptionally completes with this
exception unless this stage also completed exceptionally.
whenCompleteAsync
in interface
CompletionStage
<
T
>
action
- the action to perform
public CompletableFuture<T> whenCompleteAsync(BiConsumer<? super T,? super Throwable> action, Executor executor)
CompletionStage
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. If the supplied action itself encounters an
exception, then the returned stage exceptionally completes with this
exception unless this stage also completed exceptionally.
whenCompleteAsync
in interface
CompletionStage
<
T
>
action
- the action to perform
executor
- the executor to use for asynchronous execution
public <U> CompletableFuture<U> handle(BiFunction<? super T,Throwable,? extends U> fn)
CompletionStage
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.
handle
in interface
CompletionStage
<
T
>
U
- the function's return type
fn
- the function to use to compute the value of the
returned CompletionStage
public <U> CompletableFuture<U> handleAsync(BiFunction<? super T,Throwable,? extends U> fn)
CompletionStage
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.
handleAsync
in interface
CompletionStage
<
T
>
U
- the function's return type
fn
- the function to use to compute the value of the
returned CompletionStage
public <U> CompletableFuture<U> handleAsync(BiFunction<? super T,Throwable,? extends U> fn, Executor executor)
CompletionStage
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.
handleAsync
in interface
CompletionStage
<
T
>
U
- the function's return type
fn
- the function to use to compute the value of the
returned CompletionStage
executor
- the executor to use for asynchronous execution
public CompletableFuture<T> toCompletableFuture()
toCompletableFuture
in interface
CompletionStage
<
T
>
public CompletableFuture<T> exceptionally(Function<Throwable,? extends T> fn)
whenComplete
and
handle
.
exceptionally
in interface
CompletionStage
<
T
>
fn
- the function to use to compute the value of the
returned CompletableFuture if this CompletableFuture completed
exceptionally
public static CompletableFuture<Void> allOf(CompletableFuture<?>... cfs)
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();
.
cfs
- the CompletableFutures
NullPointerException
- if the array or any of its elements are
public static CompletableFuture<Object> anyOf(CompletableFuture<?>... cfs)
cfs
- the CompletableFutures
NullPointerException
- if the array or any of its elements are
public boolean cancel(boolean mayInterruptIfRunning)
CancellationException
. Dependent CompletableFutures
that have not already completed will also complete
exceptionally, with a
CompletionException
caused by
this
CancellationException
.
cancel
in interface
Future
<
T
>
mayInterruptIfRunning
- this value has no effect in this
implementation because interrupts are not used to control
processing.
true
if this task is now cancelled
public boolean isCancelled()
true
if this CompletableFuture was cancelled
before it completed normally.
isCancelled
in interface
Future
<
T
>
true
if this CompletableFuture was cancelled
before it completed normally
public boolean isCompletedExceptionally()
true
if this CompletableFuture completed
exceptionally, in any way. Possible causes include
cancellation, explicit invocation of
completeExceptionally
, and abrupt termination of a
CompletionStage action.
true
if this CompletableFuture completed
exceptionally
public void obtrudeValue(T value)
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.
value
- the completion value
public void obtrudeException(Throwable ex)
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.
ex
- the exception
NullPointerException
- if the exception is null
public int getNumberOfDependents()
public String toString()
"Completed Normally"
or the String
"Completed Exceptionally"
, or the String
"Not
completed"
followed by the number of CompletableFutures
dependent upon its completion, if any.
toString
in class
Object
飞奔的莲藕 · js如何引用json文件路径 | PingCode智库 2 月前 |