public void awaitRunning(final long timeout,final TimeUnit unit) throws InterruptedException, TimeoutException {
  final long begin=System.nanoTime();
  final long nanos=unit.toNanos(timeout);
  long remaining=nanos;
  if (lock.tryLock(remaining,TimeUnit.NANOSECONDS)) {
    try {
      while (!open) {
        remaining=nanos - (System.nanoTime() - begin);
        if (!running.await(remaining,TimeUnit.NANOSECONDS)) {
          break;
        }
      }
      if (open)       return;
    }
  finally {
      lock.unlock();
    }
  }
  throw new TimeoutException();
}

public void awaitRunning ( final long timeout , final TimeUnit unit ) throws InterruptedException , TimeoutException { final long begin = System . nanoTime ( ) ; final long nanos = unit . toNanos ( timeout ) ; long remaining = nanos ; if ( lock . tryLock ( remaining , TimeUnit . NANOSECONDS ) ) { try { while ( ! open ) { remaining = nanos - ( System . nanoTime ( ) - begin ) ; if ( ! running . await ( remaining , TimeUnit . NANOSECONDS ) ) { break ; } } if ( open ) return ; } finally { lock . unlock ( ) ; } } throw new TimeoutException ( ) ; }
wait until the service is running .
