Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/util/concurrent/Future.java
          +++ new/src/share/classes/java/util/concurrent/Future.java
↓ open down ↓ 39 lines elided ↑ open up ↑
  40   40   * computation.  Methods are provided to check if the computation is
  41   41   * complete, to wait for its completion, and to retrieve the result of
  42   42   * the computation.  The result can only be retrieved using method
  43   43   * <tt>get</tt> when the computation has completed, blocking if
  44   44   * necessary until it is ready.  Cancellation is performed by the
  45   45   * <tt>cancel</tt> method.  Additional methods are provided to
  46   46   * determine if the task completed normally or was cancelled. Once a
  47   47   * computation has completed, the computation cannot be cancelled.
  48   48   * If you would like to use a <tt>Future</tt> for the sake
  49   49   * of cancellability but not provide a usable result, you can
  50      - * declare types of the form <tt>Future&lt;?&gt;</tt> and
       50 + * declare types of the form {@code Future<?>} and
  51   51   * return <tt>null</tt> as a result of the underlying task.
  52   52   *
  53   53   * <p>
  54   54   * <b>Sample Usage</b> (Note that the following classes are all
  55   55   * made-up.) <p>
  56      - * <pre>
       56 + *  <pre> {@code
  57   57   * interface ArchiveSearcher { String search(String target); }
  58   58   * class App {
  59   59   *   ExecutorService executor = ...
  60   60   *   ArchiveSearcher searcher = ...
  61   61   *   void showSearch(final String target)
  62   62   *       throws InterruptedException {
  63      - *     Future&lt;String&gt; future
  64      - *       = executor.submit(new Callable&lt;String&gt;() {
       63 + *     Future<String> future
       64 + *       = executor.submit(new Callable<String>() {
  65   65   *         public String call() {
  66   66   *             return searcher.search(target);
  67   67   *         }});
  68   68   *     displayOtherThings(); // do other things while searching
  69   69   *     try {
  70   70   *       displayText(future.get()); // use future
  71   71   *     } catch (ExecutionException ex) { cleanup(); return; }
  72   72   *   }
  73      - * }
  74      - * </pre>
       73 + * }}</pre>
  75   74   *
  76   75   * The {@link FutureTask} class is an implementation of <tt>Future</tt> that
  77   76   * implements <tt>Runnable</tt>, and so may be executed by an <tt>Executor</tt>.
  78   77   * For example, the above construction with <tt>submit</tt> could be replaced by:
  79      - * <pre>
  80      - *     FutureTask&lt;String&gt; future =
  81      - *       new FutureTask&lt;String&gt;(new Callable&lt;String&gt;() {
       78 + *  <pre> {@code
       79 + *     FutureTask<String> future =
       80 + *       new FutureTask<String>(new Callable<String>() {
  82   81   *         public String call() {
  83   82   *           return searcher.search(target);
  84   83   *       }});
  85      - *     executor.execute(future);
  86      - * </pre>
       84 + *     executor.execute(future);}</pre>
  87   85   *
  88   86   * <p>Memory consistency effects: Actions taken by the asynchronous computation
  89   87   * <a href="package-summary.html#MemoryVisibility"> <i>happen-before</i></a>
  90   88   * actions following the corresponding {@code Future.get()} in another thread.
  91   89   *
  92   90   * @see FutureTask
  93   91   * @see Executor
  94   92   * @since 1.5
  95   93   * @author Doug Lea
  96   94   * @param <V> The result type returned by this Future's <tt>get</tt> method
↓ open down ↓ 75 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX