Interface Future<V>
- Type Parameters:
V- the type of the result
- All Known Implementing Classes:
AsyncResult, AsyncTask
public interface Future<V>
The result of work that finishes later -- on the backend, what an
@Async
method returns, completed when its body has run on its executor.-
Method Summary
Modifier and TypeMethodDescriptionbooleancancel(boolean mayInterruptIfRunning) Stops the work if it has not started.get()Waits for the work to finish and returns its result.Waits up totimeoutfor the work to finish and returns its result.booleanWhethercancel(boolean)cancelled the work before it ran.booleanisDone()Whether the work has finished: completed, failed or cancelled.
-
Method Details
-
cancel
boolean cancel(boolean mayInterruptIfRunning) Stops the work if it has not started. Answers whether it was cancelled; work already running is not interrupted by the backend's executors.- Parameters:
mayInterruptIfRunning- whether a running task may be interrupted- Returns:
- true when this call cancelled it
-
isCancelled
boolean isCancelled()Whethercancel(boolean)cancelled the work before it ran.- Returns:
- true when cancelled
-
isDone
boolean isDone()Whether the work has finished: completed, failed or cancelled.- Returns:
- true once it will not change again
-
get
Waits for the work to finish and returns its result.- Returns:
- the result
- Throws:
InterruptedException- when the waiting thread is interruptedExecutionException- when the work threw;Throwable.getCause()is what it threwCancellationException- when the work was cancelled
-
get
V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Waits up totimeoutfor the work to finish and returns its result.- Parameters:
timeout- how long to wait, inunitunit- the unit oftimeout- Returns:
- the result
- Throws:
InterruptedException- when the waiting thread is interruptedExecutionException- when the work threwTimeoutException- when it has not finished in timeCancellationException- when the work was cancelled
-