code: private void cleanUpDriverResources() {
      ctrlc.setComplete();
      try {
        Runtime.getRuntime().removeShutdownHook(ctrlc);
      }
      catch (IllegalStateException ignore) {
        // If "Shutdown in progress" exception would be thrown, just ignore and don't bother to remove the hook.
      }
      ctrlc = null;
  
      try {
        setShutdownRequested();
        driverCallbackSocket.close();
        driverCallbackSocket = null;
      }
      catch (Exception e) {
        System.out.println("ERROR: " + (e.getMessage() != null ? e.getMessage() : "(null)"));
        e.printStackTrace();
      }
  
      // At this point, resources are released.
      // The hadoop job has completed (job.isComplete() is true),
      // so the cluster memory and cpus are freed.
      // The driverCallbackSocket has been closed so a new one can be made.
  
      // The callbackManager itself may or may not have finished, but it doesn't
      // matter since the server socket has been closed.
    }
docs: /*
  Clean up driver-side resources after the hadoop job has finished.
  
  This method was added so that it can be called from inside
  Spring Hadoop and the driver can be created and then deleted from inside
  a single process.