code: public void close() {
          Thread responseThread = null;
          synchronized (this) {
              if (!closed) {
                  closed = true;
                  notifyAll();
  
                  if (listenForCommands) {
                      listenForCommands = false;
                      if (listeningThread != null) {
                          listeningThread.interrupt();
                      }
                  }
  
                  Utils.tryToClose(serverSocketChannel);
                  commandFile.delete();
  
                  responseThread = this.responseThread.getAndSet(null);
              }
          }
  
          if (responseThread != null) {
              try {
                  responseThread.join();
              } catch (InterruptedException ex) {
              }
          }
      }
docs: Finish any outstanding asynchronous responses, and close the server
  socket to prevent new command requests.