Code example for CountDownLatch

Methods: countDown

0
  } 
 
  void receive() { 
    if (received != -1 || sent == -1) throw new IllegalStateException();
    received = System.nanoTime();
    latch.countDown();
  } 
 
  void cancel() { 
    if (received != -1 || sent == -1) throw new IllegalStateException();
    received = sent - 1;
    latch.countDown();
  } 
 
  /** 
   * 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();