code: public static void shutdown(Duration timeout, ExecutorService... pools) {
          // Prevent new tasks from being submitted.
          for (ExecutorService pool : pools) {
              pool.shutdown();
          }
  
          TimeoutTimer timer = new TimeoutTimer(timeout);
          for (ExecutorService pool : pools) {
              try {
                  // Wait a while for existing tasks to terminate. Note that subsequent pools will be given a smaller timeout,
                  // since they all started shutting down at the same time (above), and they can shut down in parallel.
                  if (!pool.awaitTermination(timer.getRemaining().toMillis(), TimeUnit.MILLISECONDS)) {
                      // Cancel currently executing tasks and wait for them to respond to being cancelled.
                      pool.shutdownNow();
                      pool.awaitTermination(timer.getRemaining().toMillis(), TimeUnit.MILLISECONDS);
                  }
              } catch (InterruptedException ie) {
                  pool.shutdownNow();
                  Thread.currentThread().interrupt();
              }
          }
      }
docs: Shuts down the given ExecutorServices in two phases:
  1. Prevents new tasks from being submitted.
  2. Awaits for currently running tasks to terminate. If they don't terminate within the given timeout, they will be
  forcibly cancelled.
  
  This is implemented as per the guidelines in the ExecutorService Javadoc:
  https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html
  
  @param timeout Grace period that will be given to tasks to complete.
  @param pools   The ExecutorServices to shut down.