Integrated: 8267140: Support closing the HttpClient by making it auto-closable

Daniel Fuchs dfuchs at openjdk.org
Thu Apr 6 10:09:36 UTC 2023


On Tue, 14 Mar 2023 14:18:49 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.

This pull request has now been integrated.

Changeset: 6580c4e6
Author:    Daniel Fuchs <dfuchs at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/6580c4e6311b6f87cec7c5c5537351bec9b703db
Stats:     2401 lines in 12 files changed: 2249 ins; 2 del; 150 mod

8267140: Support closing the HttpClient by making it auto-closable

Reviewed-by: jpai

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

PR: https://git.openjdk.org/jdk/pull/13019


More information about the net-dev mailing list