RFR: 8267140: Support closing the HttpClient by making it auto-closable [v11]
Daniel Fuchs
dfuchs at openjdk.org
Wed Mar 22 11:15:38 UTC 2023
> Please find here an RFE that makes the `java.net.HttpClient` auto-closeable.
>
> The API has been modeled on `ExecutorService`.
>
> HttpClient::close() is a graceful shutdown and will wait until all operations are terminated before returning.
> If a request is in progress, and the caller doesn't pull the corresponding data (for instance, the request was sent with a BodyHandler.ofInputStream(), but the caller stopped reading the input stream) then close() may never return.
>
> Therefore, additional methods similar to those present in `ExecutorService` are also proposed. In summary:
>
> - `shutdown()`: initiate a graceful shutdown, but doesn't wait for termination.
> - `shutdownNow()`: initiate an immediate shutdown, attempting to cancel all operations in progress. Doesn't wait for termination.
> - `awaitTermination(Duration)`: await for termination within the given delay
> - `isTerminated()` tells whether the client is terminated
>
> New tests have been added to test the proposed behaviors.
>
> HttpClient tests (new and old) are still stable.
Daniel Fuchs has updated the pull request incrementally with two additional commits since the last revision:
- Minor updates. Added some links
- Define operations. Clarify some of the things that may stall an orderly shutdown
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/13019/files
- new: https://git.openjdk.org/jdk/pull/13019/files/dd4f8f79..2fca2991
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=13019&range=10
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=13019&range=09-10
Stats: 41 lines in 1 file changed: 29 ins; 0 del; 12 mod
Patch: https://git.openjdk.org/jdk/pull/13019.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/13019/head:pull/13019
PR: https://git.openjdk.org/jdk/pull/13019
More information about the net-dev
mailing list