Code example for CountDownLatch

Methods: await

0
   * Returns the round trip time for this ping in nanoseconds, waiting for the 
   * response to arrive if necessary. Returns -1 if the response was 
   * cancelled. 
   */ 
  public long roundTripTime() throws InterruptedException { 
    latch.await();
    return received - sent;
  } 
 
  /** 
   * Returns the round trip time for this ping in nanoseconds, or -1 if the 
   * response was cancelled, or -2 if the timeout elapsed before the round 
   * trip completed. 
   */ 
  public long roundTripTime(long timeout, TimeUnit unit) throws InterruptedException {
    if (latch.await(timeout, unit)) {
      return received - sent;
    } else { 
      return -2; 
    } 
  }