> The teardown of a Process launched by `ProcessBuilder` includes the closing > of streams and ensuring the termination of the process is the responsibility > of the caller. The `Process.close()` method provides a clear and obvious way > to ensure all the streams are closed and the process terminated. > > The try-with-resources statement is frequently used to open streams and > ensure they are closed on exiting the block. By implementing > `AutoClosable.close()` the completeness of closing the streams and process > termination can be done by try-with-resources. > > The actions of the `close()` method are to close each stream and destroy the > process if it has not terminated.
Roger Riggs has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 16 additional commits since the last revision: - Merge branch 'master' into 8364361-process-autocloseable - Address review comments for code and javadoc in Process, the test and the example. Reinforced that calling waitFor should occur before calling close to wait for termination and get the exitStatus. Corrected the error message check for invalid handles on Windows. Update test to allow normal completion when exceptions may be expected. Correct the expected message on Windows for an invalid handle exception. - Update close() to use "terminate" consistently. - Remove volatile from "closed" field; updates are guarded by synchronized. - The CSR review prompted the expansion of the description of responsibilities of subclasses of Process to invoke `super.close()` if overriding the `close()` method. - Monor improvements to javadoc, move close() near the constructor to make it more prominent in the javadoc. - Merge branch 'master' into 8364361-process-autocloseable - Expand the description of close() to describe the behavior of destroying the process. - javadoc tweaks - Misc, javadoc cleanup Simplified the Interrupt handling in ProcessCloseTest.ProcessCommand.ExpectExit. - ... and 6 more: https://git.openjdk.org/jdk/compare/2991ed29...5a0c5602 ------------- Changes: - all: https://git.openjdk.org/jdk/pull/26649/files - new: https://git.openjdk.org/jdk/pull/26649/files/f57dc160..5a0c5602 Webrevs: - full: https://webrevs.openjdk.org/?repo=jdk&pr=26649&range=11 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=26649&range=10-11 Stats: 186286 lines in 2309 files changed: 145081 ins; 26567 del; 14638 mod Patch: https://git.openjdk.org/jdk/pull/26649.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/26649/head:pull/26649 PR: https://git.openjdk.org/jdk/pull/26649
