Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/util/concurrent/Executor.java
          +++ new/src/share/classes/java/util/concurrent/Executor.java
↓ open down ↓ 71 lines elided ↑ open up ↑
  72   72   *     public void execute(Runnable r) {
  73   73   *         new Thread(r).start();
  74   74   *     }
  75   75   * }</pre>
  76   76   *
  77   77   * Many <tt>Executor</tt> implementations impose some sort of
  78   78   * limitation on how and when tasks are scheduled.  The executor below
  79   79   * serializes the submission of tasks to a second executor,
  80   80   * illustrating a composite executor.
  81   81   *
  82      - * <pre>
       82 + *  <pre> {@code
  83   83   * class SerialExecutor implements Executor {
  84      - *     final Queue&lt;Runnable&gt; tasks = new ArrayDeque&lt;Runnable&gt;();
  85      - *     final Executor executor;
  86      - *     Runnable active;
       84 + *   final Queue<Runnable> tasks = new ArrayDeque<Runnable>();
       85 + *   final Executor executor;
       86 + *   Runnable active;
  87   87   *
  88      - *     SerialExecutor(Executor executor) {
  89      - *         this.executor = executor;
  90      - *     }
       88 + *   SerialExecutor(Executor executor) {
       89 + *     this.executor = executor;
       90 + *   }
  91   91   *
  92      - *     public synchronized void execute(final Runnable r) {
  93      - *         tasks.offer(new Runnable() {
  94      - *             public void run() {
  95      - *                 try {
  96      - *                     r.run();
  97      - *                 } finally {
  98      - *                     scheduleNext();
  99      - *                 }
 100      - *             }
 101      - *         });
 102      - *         if (active == null) {
 103      - *             scheduleNext();
       92 + *   public synchronized void execute(final Runnable r) {
       93 + *     tasks.offer(new Runnable() {
       94 + *       public void run() {
       95 + *         try {
       96 + *           r.run();
       97 + *         } finally {
       98 + *           scheduleNext();
 104   99   *         }
      100 + *       }
      101 + *     });
      102 + *     if (active == null) {
      103 + *       scheduleNext();
 105  104   *     }
      105 + *   }
 106  106   *
 107      - *     protected synchronized void scheduleNext() {
 108      - *         if ((active = tasks.poll()) != null) {
 109      - *             executor.execute(active);
 110      - *         }
      107 + *   protected synchronized void scheduleNext() {
      108 + *     if ((active = tasks.poll()) != null) {
      109 + *       executor.execute(active);
 111  110   *     }
 112      - * }</pre>
      111 + *   }
      112 + * }}</pre>
 113  113   *
 114  114   * The <tt>Executor</tt> implementations provided in this package
 115  115   * implement {@link ExecutorService}, which is a more extensive
 116  116   * interface.  The {@link ThreadPoolExecutor} class provides an
 117  117   * extensible thread pool implementation. The {@link Executors} class
 118  118   * provides convenient factory methods for these Executors.
 119  119   *
 120  120   * <p>Memory consistency effects: Actions in a thread prior to
 121  121   * submitting a {@code Runnable} object to an {@code Executor}
 122  122   * <a href="package-summary.html#MemoryVisibility"><i>happen-before</i></a>
↓ open down ↓ 19 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX