T
- operation result representation.public static class Operations.CompletedFuture<T> extends Object implements Future<T>
Future
in the completed state with a fixed result.
The outcome of the future cannot be altered and it cannot be cancelled.Constructor and Description |
---|
CompletedFuture(T result) |
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning)
Attempts to cancel execution of this task.
|
T |
get()
Waits if necessary for the computation to complete, and then retrieves its result.
|
T |
get(long timeout,
TimeUnit unit)
Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if
available.
|
boolean |
isCancelled()
Returns true if this task was cancelled before it completed normally.
|
boolean |
isDone()
Returns true if this task completed.
|
public CompletedFuture(T result)
public boolean cancel(boolean mayInterruptIfRunning)
Future
After this method returns, subsequent calls to Future.isDone()
will always return true. Subsequent calls
to Future.isCancelled()
will always return true if this method returned true.
cancel
in interface Future<T>
mayInterruptIfRunning
- true if the thread executing this task should be interrupted; otherwise, in-progress tasks
are allowed to completepublic T get() throws InterruptedException, ExecutionException
Future
get
in interface Future<T>
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the computation threw an exceptionpublic T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
Future
get
in interface Future<T>
timeout
- the maximum time to waitunit
- the time unit of the timeout argumentInterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the computation threw an exceptionTimeoutException
- if the wait timed outpublic boolean isCancelled()
Future
isCancelled
in interface Future<T>
public boolean isDone()
Future