RFR: 8267140: Support closing the HttpClient by making it auto-closable [v17]

Jaikiran Pai jpai at openjdk.org
Thu Apr 6 10:05:27 UTC 2023


On Thu, 6 Apr 2023 09:52:36 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> 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 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 25 additional commits since the last revision:
> 
>  - Merge branch 'master' into HttpClient-close-8267140
>  - Further CSR review feedback
>  - Merge branch 'master' into HttpClient-close-8267140
>  - Included CSR review feedback
>  - Merge branch 'master' into HttpClient-close-8267140
>  - Fixed minor typos in test comments
>  - Integrated feedback on tests
>  - Minor updates. Added some links
>  - Define operations. Clarify some of the things that may stall an orderly shutdown
>  - Update src/java.net.http/share/classes/java/net/http/HttpClient.java
>    
>    Fixed typo
>  - ... and 15 more: https://git.openjdk.org/jdk/compare/69a729e4...4ebfca14

Marked as reviewed by jpai (Reviewer).

Hello Daniel, the latest documentation changes all look fine to me.

As for:

>
>     2. An `@see ##closing Implementation Note on closing the HttpClient` is added instead, at the end of the method API documentation.

I haven't previously used this construct in a `@see`, so as long as the generated javadoc renders fine, this looks good. Does it render a `<a href=...>Implementation Note on closing the HttpClient</a>`?

-------------

PR Review: https://git.openjdk.org/jdk/pull/13019#pullrequestreview-1374504350
PR Comment: https://git.openjdk.org/jdk/pull/13019#issuecomment-1498802890


More information about the net-dev mailing list