public static void awaitUntil(Clock clock, Object lock, long endTime)
    throws InterruptedException, TimeoutException
  {
    if(endTime <= 0)
      lock.wait();
    else
    {
      long now = clock.currentTimeMillis();
      if(now >= endTime)
        throw new TimeoutException("timeout reached while waiting on the lock: "
                                   + lock);
      lock.wait(endTime - now);
    }
  }
public static void awaitUntil(Clock clock, Object lock, long endTime)
    throws InterruptedException, TimeoutException
  {
    if(endTime <= 0)
      lock.wait();
    else
    {
      long now = clock.currentTimeMillis();
      if(now >= endTime)
        throw new TimeoutException("timeout reached while waiting on the lock: "
                                   + lock);
      lock.wait(endTime - now);
    }
  }
public static void awaitUntil ( Clock clock , Object lock , long endTime ) throws InterruptedException , TimeoutException { if ( endTime <= 0 ) lock . wait ( ) ; else { long now = clock . currentTimeMillis ( ) ; if ( now >= endTime ) throw new TimeoutException ( "timeout reached while waiting on the lock: " + lock ) ; lock . wait ( endTime - now ) ; } }
Waits on the lock but if end time is expired then throws an
exception. On purpose this method does not synchronize on the lock
because it must be called from a block which synchronizes on it

@param lock the lock to wait on
@param endTime the time after which an exception is thrown (compared
to {@link java.lang.System#currentTimeMillis()}. If &lt; 0 then wait
indefinitely (so <code>TimeOutException</code> will not be thrown!)
@throws InterruptedException if the thread is interrupted while waiting
@throws TimeoutException if the time has been reached
Waits on the lock but if end time is expired then throws an exception . On purpose this method does not synchronize on the lock because it must be called from a block which synchronizes on it