Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

edu.emory.mathcs.util.concurrent
Interface Future  view Future download Future.java

All Known Implementing Classes:
AsyncTask, CompletedFuture

public interface Future

A Future represents the result of an asynchronous computation. Methods are provided to check if the computation is complete, to wait for its completion, and to retrieve the result of the computation. The result can only be retrieved when the computation has completed. The get method will block until the computation has completed. Once the computation has completed, the result cannot be changed, nor can the computation be restarted or cancelled.

Sample Usage

 class Image { ... };
 class ImageRenderer { Image render(byte[] raw); }
 class App {
   Executor executor = ...
   ImageRenderer renderer = ...
   void display(final byte[] rawimage) throws InterruptedException {
     Future futureImage =
       new FutureTask(new Callable() {
         public Object call() {
           return renderer.render(rawImage);
       }});
     executor.execute(futureImage);
     drawBorders(); // do other things while executing
     drawCaption();
     try {
       drawImage((Image)(futureImage.get())); // use future
     }
     catch (ExecutionException ex) { cleanup(); return; }
   }
 }
 

Since:
1.5

Method Summary
 java.lang.Object get()
          Waits if necessary for computation to complete, and then retrieves its result.
 java.lang.Object get(long timeout, TimeUnit granularity)
          Waits if necessary for at most the given time for the computation to complete, and then retrieves its result.
 boolean isDone()
          Returns true if the underlying task has completed.
 

Method Detail

isDone

public boolean isDone()
Returns true if the underlying task has completed.


get

public java.lang.Object get()
                     throws java.lang.InterruptedException,
                            ExecutionException
Waits if necessary for computation to complete, and then retrieves its result.


get

public java.lang.Object get(long timeout,
                            TimeUnit granularity)
                     throws java.lang.InterruptedException,
                            ExecutionException,
                            TimeoutException
Waits if necessary for at most the given time for the computation to complete, and then retrieves its result.