public class CompletableFutureTask<R> extends CompletableFuture<R> implements Runnable
CompletableFuture
which embeds an actual task, unlike the default implementation.
In particular, the behaviour of cancel(boolean)
is modified in order to actually
interrupt the thread executing the bound task.
Similarly to FutureTask
, this class implements Runnable
and
can therefore be submitted to an Executor
for execution.
CompletableFuture.AsynchronousCompletionTask
Constructor and Description |
---|
CompletableFutureTask(Callable<R> task)
Creates a completable future bound to the specified task.
|
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning)
Cancels this completable future and, if requested and if the bound task is under execution,
interrupts the thread executing the task.
|
void |
run()
Executes the wrapped callable.
|
static <T> CompletableFutureTask<T> |
runAsync(Callable<T> task,
Executor executor)
Creates a completable future task and submits it to the specified executor.
|
CompletableFutureTask<R> |
runAsync(Executor executor)
Submits this task to the specified executor.
|
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, complete, completedFuture, completeExceptionally, exceptionally, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, obtrudeException, obtrudeValue, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsync
public void run()
public CompletableFutureTask<R> runAsync(Executor executor)
executor
- The executor which will execute this task.public static <T> CompletableFutureTask<T> runAsync(Callable<T> task, Executor executor)
task
- The task to be executed.executor
- The executor which will execute the task.CompletableFutureTask
bound to the specified task.public boolean cancel(boolean mayInterruptIfRunning)
cancel
in interface Future<R>
cancel
in class CompletableFuture<R>
mayInterruptIfRunning
- if true
, and if the bound task is under execution,
the thread executing the task will be interruptedfalse
if the task could not be cancelled,
typically because it has already completed;
true
otherwiseCopyright © 2020. All rights reserved.