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

Daniel Fuchs dfuchs at openjdk.org
Wed Apr 5 15:04:23 UTC 2023


On Wed, 5 Apr 2023 14:57:24 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 incrementally with one additional commit since the last revision:
> 
>   Further CSR review feedback

@AlanBateman suggested the following changes, with which I have updated the CSR and this PR:

In the class level documentation:

1. Only the first sentence of the previously added `@apiNote` remains in the `@apiNote`
2. The bulk of the `@apiNote` text that was added previously is now moved to the `@implNote` paragraph
3. The modified `@apiNote` is moved above the `@implNote` that was previously there
4. The `##closing` anchor now links to the `@implNote`

In each of the new methods:

1. The link to the `##closing` paragraph (non-normative) is removed from the `@implSpec` (normative).
2. An `@see ##closing Implementation Note on closing the HttpClient` is added instead, at the end of the method API documentation.

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

PR Comment: https://git.openjdk.org/jdk/pull/13019#issuecomment-1497640779


More information about the net-dev mailing list