ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/Phaser.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/Phaser.java (file contents):
Revision 1.7 by jsr166, Wed Aug 12 04:10:59 2009 UTC vs.
Revision 1.8 by jsr166, Wed Aug 19 18:07:36 2009 UTC

# Line 93 | Line 93 | import java.util.concurrent.locks.LockSu
93   * first register, then start the actions, then deregister, as in:
94   *
95   *  <pre> {@code
96 < * void runTasks(List<Runnable> list) {
96 > * void runTasks(List<Runnable> tasks) {
97   *   final Phaser phaser = new Phaser(1); // "1" to register self
98   *   // create and start threads
99 < *   for (Runnable r : list) {
99 > *   for (Runnable task : tasks) {
100   *     phaser.register();
101   *     new Thread() {
102   *       public void run() {
103   *         phaser.arriveAndAwaitAdvance(); // await all creation
104 < *         r.run();
104 > *         task.run();
105   *       }
106   *     }.start();
107   *   }
# Line 114 | Line 114 | import java.util.concurrent.locks.LockSu
114   * for a given number of iterations is to override {@code onAdvance}:
115   *
116   *  <pre> {@code
117 < * void startTasks(List<Runnable> list, final int iterations) {
117 > * void startTasks(List<Runnable> tasks, final int iterations) {
118   *   final Phaser phaser = new Phaser() {
119   *     public boolean onAdvance(int phase, int registeredParties) {
120   *       return phase >= iterations || registeredParties == 0;
121   *     }
122   *   };
123   *   phaser.register();
124 < *   for (Runnable r : list) {
124 > *   for (Runnable task : tasks) {
125   *     phaser.register();
126   *     new Thread() {
127   *       public void run() {
128   *         do {
129 < *           r.run();
129 > *           task.run();
130   *           phaser.arriveAndAwaitAdvance();
131   *         } while(!phaser.isTerminated();
132   *       }
# Line 167 | Line 167 | import java.util.concurrent.locks.LockSu
167   *
168   * <p><b>Implementation notes</b>: This implementation restricts the
169   * maximum number of parties to 65535. Attempts to register additional
170 < * parties result in IllegalStateExceptions. However, you can and
170 > * parties result in {@code IllegalStateException}. However, you can and
171   * should create tiered phasers to accommodate arbitrarily large sets
172   * of participants.
173   *
# Line 533 | Line 533 | public class Phaser {
533  
534      /**
535       * Awaits the phase of the barrier to advance from the given phase
536 <     * value, or returns immediately if the current phase of the barrier
537 <     * is not equal to the given phase value or this barrier is
538 <     * terminated.
536 >     * value, returning immediately if the current phase of the
537 >     * barrier is not equal to the given phase value or this barrier
538 >     * is terminated.
539       *
540       * @param phase the phase on entry to this method
541       * @return the phase on exit from this method
# Line 554 | Line 554 | public class Phaser {
554      }
555  
556      /**
557 <     * Awaits the phase of the barrier to advance from the given
558 <     * value, or returns immediately if argument is negative or this
559 <     * barrier is terminated, or throws InterruptedException if
560 <     * interrupted while waiting.
557 >     * Awaits the phase of the barrier to advance from the given phase
558 >     * value, throwing {@code InterruptedException} if interrupted while
559 >     * waiting, or returning immediately if the current phase of the
560 >     * barrier is not equal to the given phase value or this barrier
561 >     * is terminated.
562       *
563       * @param phase the phase on entry to this method
564       * @return the phase on exit from this method
# Line 577 | Line 578 | public class Phaser {
578      }
579  
580      /**
581 <     * Awaits the phase of the barrier to advance from the given value
582 <     * or the given timeout elapses, or returns immediately if
583 <     * argument is negative or this barrier is terminated.
581 >     * Awaits the phase of the barrier to advance from the given phase
582 >     * value or the given timeout to elapse, throwing
583 >     * {@code InterruptedException} if interrupted while waiting, or
584 >     * returning immediately if the current phase of the barrier is not
585 >     * equal to the given phase value or this barrier is terminated.
586       *
587       * @param phase the phase on entry to this method
588 +     * @param timeout how long to wait before giving up, in units of
589 +     *        {@code unit}
590 +     * @param unit a {@code TimeUnit} determining how to interpret the
591 +     *        {@code timeout} parameter
592       * @return the phase on exit from this method
593       * @throws InterruptedException if thread interrupted while waiting
594       * @throws TimeoutException if timed out while waiting

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines