void shutdown()

in nailgun-server/src/main/java/com/facebook/nailgun/NGSessionPool.java [129:161]


  void shutdown() throws InterruptedException {
    List<NGSession> allSessions;
    synchronized (lock) {
      done = true;
      allSessions =
          Stream.concat(workingPool.stream(), idlePool.stream()).collect(Collectors.toList());
      idlePool.clear();
      workingPool.clear();
    }
    for (NGSession session : allSessions) {
      session.shutdown();
    }

    // wait for all sessions to complete by either returning from waiting state or finishing their
    // nails
    long start = System.nanoTime();
    for (NGSession session : allSessions) {
      long timeout =
          NGConstants.SESSION_TERMINATION_TIMEOUT_MILLIS
              - TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);
      if (timeout < 1) {
        // Give all threads a chance to finish or pick up already finished threads
        timeout = 1;
      }
      session.join(timeout);
      if (session.isAlive()) {
        throw new IllegalStateException(
            "NGSession has not completed in "
                + NGConstants.SESSION_TERMINATION_TIMEOUT_MILLIS
                + " ms");
      }
    }
  }