Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8342296

Make java.lang.Process AutoCloseable

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Make java.lang.Process implement AutoCloseable in order to make it possible to use in a try-with-resources block. It is too easy in exceptional cases to not properly close a Process. This could leave a Process running even outside of the life of the JVM. Additionally, there may be some InputStreams that are not closed promptly.

      The close() method could implement a graceful shutdown similar to the below pseudo code (possibly allowing the grace period to be defined in java.lang.ProcessBuilder):
        if (supportsNormalTermination()) {
          destroy();
          if (waitFor(5, TimeUnit.SECONDS)) {
            return;
          }
        }
        destroyForcibly().waitFor();

      There is precedence for adding AutoCloseable to existing abstract classes and interfaces like java.net.http.HttpClient (JDK-8304165) and java.util.concurrent.ExecutorService (JDK-8285450).


            rriggs Roger Riggs
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: