code: public void stopAndJoin() {
      interrupt();
      if (mServerSocket != null) {
        try {
          mServerSocket.close();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      try {
        join(5 * Constants.SECOND_MS);
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
      }
      if (isAlive()) {
        LOG.warn("Failed to stop rejecting server thread");
      }
    }
docs: Stops the server and joins the server thread.