Summary
Make the default keep alive time for idle TCP connections in the HttpURLConnection cache, configurable via a system property
Problem
If a server specifies a keep alive time in its response headers that is obeyed by the HttpURLConnection keep alive cache, but if the server does not specify a timeout then a hard coded default is used. This default value does not suit all use cases, and it can happen that race conditions occur where the server closes the connection just as the client tries to reuse it.
Solution
The solution is to specify system properties that can be set to alter the default keep alive period, for cases when the server does not specify a time.
Specification
The following system property definition is added to the net-properties.html file referenced by the java.net package apidoc
<LI><P><B>{@systemProperty http.keepAlive.time.server}</B> and
<B>{@systemProperty http.keepAlive.time.proxy}</B> </P>
<P>These properties modify the behavior of the HTTP keepalive cache in the case
where the server (or proxy) has not specified a keepalive time. If the
property is set in this case, then idle connections will be closed after the
specified number of seconds. If the property is set, and the server does
specify a keepalive time in a "Keep-Alive" response header, then the time specified
by the server is used. If the property is not set and also the server
does not specify a keepalive time, then connections are kept alive for an
implementation defined time, assuming {@code http.keepAlive} is {@code true}.</P>
- csr of
-
JDK-8278067 Make HttpURLConnection default keep alive timeout configurable
- Resolved