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 Type
    Method
    Description
    boolean
    cancel(boolean mayInterruptIfRunning)
    Stops the work if it has not started.
    get()
    Waits for the work to finish and returns its result.
    get(long timeout, TimeUnit unit)
    Waits up to timeout for the work to finish and returns its result.
    boolean
    Whether cancel(boolean) cancelled the work before it ran.
    boolean
    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()
      Whether cancel(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 interrupted
      ExecutionException - when the work threw; Throwable.getCause() is what it threw
      CancellationException - when the work was cancelled
    • get

      Waits up to timeout for the work to finish and returns its result.
      Parameters:
      timeout - how long to wait, in unit
      unit - the unit of timeout
      Returns:
      the result
      Throws:
      InterruptedException - when the waiting thread is interrupted
      ExecutionException - when the work threw
      TimeoutException - when it has not finished in time
      CancellationException - when the work was cancelled