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

Clarify java.lang.Process resource cleanup

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 25, 26
    • core-libs
    • None
    • minimal
    • The documentation is updated to recommend and describe how to close and release resources. There are no behavioral changes.
    • Java API
    • SE

      Summary

      The resources used to launch processes and communicate with them should be freed when no longer in use.

      Problem

      The java.lang.Process documentation does not include examples and recommendations for the use of byte and character streams and the freeing the resources used to communicate with the process.

      Solution

      The Process and ProcessBuilder documentation provides examples of closing streams used to communicate with the process. The fallback mechanisms used to prevent resource leaks are described.

      Specification

      The class javadoc for Process adds a Resource Usage section to the class javadoc with an example and recommendations for closing streams.

      The methods returning the input and error byte streams and character stream readers include the recommendation to close them when they are no longer needed. There is a recommendation to use either byte streams or character stream but not both to avoid unexpected interactions due to buffering.

      The methods returning the output byte stream and output character writer include the recommendation to close them when they are no longer needed.

      The ProcessBuilder examples are changed to use the javadoc snippet tags.

      The full text is included in the attached API diff and patch.

            rriggs Roger Riggs
            rriggs Roger Riggs
            Jaikiran Pai
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: