Code example for CountDownLatch

Methods: await, getCount

0
     *  
     * @param failureMessage 
     * @throws InterruptedException 
     */ 
    public void waitForAction( String failureMessage ) throws InterruptedException{
        countDownLatch.await( timeout, TimeUnit.MILLISECONDS );
        if( countDownLatch.getCount() > 0 ) fail( failureMessage );
    } 
 
    /** 
     * The other Thread invokes this. 
     */ 
    public void action(){ 
        countDownLatch.countDown();
    } 
 
}