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.
- csr of
-
JDK-8354872 Clarify java.lang.Process resource cleanup
-
- Resolved
-