code: private static void wait(Object lock, int timeout)
    {
      try {
        lock.wait(timeout);
      }
      catch(InterruptedException unused) {
        Thread.currentThread().interrupt();
      }
    }
docs: Wait notification on synchronized object for specified period of time. If timeout is zero this method blocks till
  notification arrive.
  
  @param lock synchronized object to wait on, possible zero,
  @param timeout timeout in milliseconds.