title: Java thread has "join()" to wait all threads, then what use case do we need CyclicBarrier?
body: <p>JDK doc says:</p>
  <pre><code>public class CyclicBarrier
  extends Object
  
  A synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point. CyclicBarriers are useful in programs involving a fixed sized party of threads that must occasionally wait for each other. The barrier is called cyclic because it can be re-used after the waiting threads are released.
  A CyclicBarrier supports an optional Runnable command that is run once per barrier point, after the last thread in the party arrives, but before any threads are released. This barrier action is useful for updating shared-state before any of the parties continue.
  </code></pre>
  <p>Then it gives a sample code, it works.</p>
  <pre><code>class Worker implements Runnable {
       int myRow;
       Worker(int row) { myRow = row; }
       public void run() {
         while (!done()) {
           processRow(myRow);
  
           try {
             barrier.await();
           } catch (InterruptedException ex) {
  ...
  class Solver
  ...
       List&lt;Thread&gt; threads = new ArrayList&lt;Thread&gt;(N);
       for (int i = 0; i &lt; N; i++) {
         Thread thread = new Thread(new Worker(i));
         threads.add(thread);
         thread.start();
       }
  
       // wait until done
       for (Thread thread : threads)
         thread.join(); // here we still need to wait all threads using join()
  ...
  </code></pre>
  <p>But still CyclicBarrier here seems redundant to me: threads &quot;wait for each other&quot;, which is done by the <code>for</code> loop that calls <code>thread.join()</code></p>
  <p>In any case, as long as I wish to collect all results from threads, I'll have to wait for them to finish, right? If Thread.join() works, then why, or in what scenario do we need to introduce CyclicBarrier(ocam's razor?)</p>