code: private void closeThreads() throws IOException {
      try {
        if (streamer != null) {
          streamer.close();
          streamer.join();
        }
  
        // shutdown response after streamer has exited.
        if (response != null) {
          response.close();
          response.join();
          response = null;
        }
      } catch (InterruptedException e) {
        throw new InterruptedIOException("Failed to shutdown response thread");
      }
    }
docs: shutdown datastreamer and responseprocessor threads.