code: public synchronized void addShutdownListener(ShutdownListener listener) {
          if (state == CLOSED) {
              listener.handleCompleted();
          } else {
              listeners.add(listener);
          }
      }
docs: Add a shutdown listener, which gets called when all requests completed on shutdown.
  
  @param listener    the shutdown listener