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

Comparing jsr166/src/jsr166y/Phaser.java (file contents):
Revision 1.29 by jsr166, Wed Aug 12 04:02:45 2009 UTC vs.
Revision 1.33 by jsr166, Wed Aug 19 18:00:55 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines