I'm using Java 11 HttpClient to send request to a remote server.
I wanted to know if there is a difference on the HttpClient object when creating object in below 2 different ways
HttpClient client = HttpClient.newHttpClient();
vs
HttpClient client = HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).
.connectTimeout(Duration.ofMillis(2000))
.build();
For Starters,
There seems to be no provision to set
connectTimeout
when creating object usingHttpClient.newHttpClient()
Also, as per this question, it appears a default connection pool (UNLIMITED connections) is created with
keepalive.timeout=1200
seconds only when theHTTPCLient
object is created usingHttpClient.newHttpClient()
.
Does this not happen when it is created using the following?
HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).
.connectTimeout(Duration.ofMillis(connectionTimeout))
.build()
I want to leverage automatic connection pool creation of Java 11 HTTPClient with my custom keepalive.timeout=120
sec and still be able to also set connectTimeout
value.
Please advise, TIA.