title: What is the purpose of await() in CountDownLatch?
body: <p>I have the following program, where I am using <code>java.util.concurrent.CountDownLatch</code> and without using <code>await()</code> method it's working fine.</p>
  <p>I am new to concurrency and want to know the purpose of <code>await()</code>. In <code>CyclicBarrier</code> I can understand why <code>await()</code> is needed, but why in <code>CountDownLatch</code>?</p>
  <p>Class <code>CountDownLatchSimple</code>:</p>
  <pre><code>public static void main(String args[]) {
    CountDownLatch latch = new CountDownLatch(3);
    Thread one = new Thread(new Runner(latch),&quot;one&quot;);
    Thread two = new Thread(new Runner(latch), &quot;two&quot;);
    Thread three = new Thread(new Runner(latch), &quot;three&quot;);
  
    // Starting all the threads
    one.start(); two.start(); three.start();
    
  }
  </code></pre>
  <p>Class <code>Runner</code> implements <code>Runnable</code>:</p>
  <pre><code>CountDownLatch latch;
  
  public Runner(CountDownLatch latch) {
      this.latch = latch;
  }
  
  @Override
  public void run() {
      System.out.println(Thread.currentThread().getName()+&quot; is Waiting.&quot;);
      try {
          Thread.sleep(2000);
      } catch (InterruptedException e) {
          e.printStackTrace();
      }
      latch.countDown();
      System.out.println(Thread.currentThread().getName()+&quot; is Completed.&quot;);
  }
  </code></pre>
  <h3>OUTPUT</h3>
  <blockquote>
  <p>two is Waiting.<br />
  three is Waiting.<br />
  one is Waiting.<br />
  one is Completed.<br />
  two is Completed.<br />
  three is Completed.</p>
  </blockquote>