code: public void waitFor(long timeout) throws JSchException, ExitCode, InterruptedException {
          long deadline;
  
          try {
              deadline = System.currentTimeMillis() + timeout;
              while (!channel.isClosed()) {
                  if (System.currentTimeMillis() >= deadline) {
                      throw new TimeoutException(this);
                  }
                  Thread.sleep(100); // throws InterruptedException
              }
              if (channel.getExitStatus() != 0) {
                  throw new ExitCode(new Launcher(command), channel.getExitStatus());
              }
          } finally {
              channel.disconnect();
          }
      }
docs: Waits for termination.
  
  @param timeout CAUTION: &lt;= 0 immediately times out