T
- the future result type of an asynchronous operation.@Contract(threading=IMMUTABLE) public class CompletedFuture<T> extends Object implements Future<T>, Cancellable
Constructor and Description |
---|
CompletedFuture(T result) |
Modifier and Type | Method and Description |
---|---|
boolean |
cancel()
Cancels the ongoing operation or process.
|
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()
Cancellable
cancel
in interface Cancellable
true
if the operation or process has been cancelled as a result of
this method call or false
if it has already been cancelled or not started.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()
Future
public T get(long timeout, TimeUnit unit)
Future
public boolean isCancelled()
Future
isCancelled
in interface Future<T>
public boolean isDone()
Future