fewkfwk fewfw
fewkfwk fewfw

Reputation: 61

HttpClient close connection

I would like to ask if this code after execution is auto-closing the connection. Also if it fail and crash, is it still going to close connection?

HttpClient.newHttpClient().send(
    HttpRequest.newBuilder()
        .uri(URI.create("url_website"))
        .timeout(Duration.ofSeconds(5))
        .GET()
        .build(),
    HttpResponse.BodyHandlers.ofString())
.body()

Upvotes: 5

Views: 1548

Answers (1)

daniel
daniel

Reputation: 3288

The HttpClient uses a connection pool (one for HTTP/1.1, one for HTTP/2) so connections will be pooled - and therefore not closed immediately unless requested by the server (HTTP/1.1: connection: close).

Upvotes: 2

Related Questions