Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For Phaser I have answered a few questions. Seeing them may help in understanding their applications. They are linked at the bottom. But to understand what the Phaser does and why its useful its important to know what it solves. </p> <p>Here are attributes of a CountdownLatch and CyclicBarrier</p> <p>Note: </p> <ul> <li>Number of parties is another way of saying # of different threads</li> <li>Not Reusable means you will have to create a new instance of the barrier before reusing</li> <li>A barrier is advanceable if a thread can arrive and continue doing work without waiting for others or can wait for all threads to complete</li> </ul> <p><strong><em>CountdownLatch</em></strong></p> <ul> <li>Fixed number of parties</li> <li>Not resuable </li> <li>Advanceable (look at <code>latch.countDown();</code> <strong>advanceable</strong> <code>latch.await();</code> <strong>must wait</strong> )</li> </ul> <p><strong><em>CyclicBarrier</em></strong></p> <ul> <li>Fixed number of parties</li> <li>Reusable</li> <li>Not advanceable</li> </ul> <p>So the CountdownLatch is not reusable, you must create a new instance each time, but is avanceable. CylicBarrier can be re used but all threads must wait for each party to arrive at the barrier.</p> <p><strong><em>Phaser</em></strong></p> <ul> <li>Dynamic number of parties</li> <li>Reusable</li> <li>Advanceable</li> </ul> <p>When a thread wants to be known to the Phaser they invoke <code>phaser.register()</code> when the thread arrives at the barrier they invoke <code>phaser.arrive()</code> <strong>and here is where it is advanceable</strong>. If the thread wants to await for all registered tasks to complete <code>phaser.arriveAndAwaitAdvance()</code></p> <p>There is also the concept of a phase in which threads can wait on a completion of a other operations that may have not completed. Once all threads arrive at the phaser's barrier a new phase is created (an increment of one). </p> <p>You can take a look at my other answers, maybe it will help:</p> <p><a href="https://stackoverflow.com/questions/4958330/java-executorservice-awaittermination-of-all-recursively-created-tasks/4958476#4958476">Java ExecutorService: awaitTermination of all recursively created tasks</a></p> <p><a href="https://stackoverflow.com/questions/1636194/flexible-countdownlatch/1637030#1637030">Flexible CountDownLatch?</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload