HttpClient close connection

1.2k views Asked by At

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()
1

There are 1 answers

0
daniel On

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).