Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8326435

Make HttpURLConnection default keep alive timeout configurable

XMLWordPrintable

    • behavioral
    • minimal
    • The current behavior is maintained for the case where the properties are not set.
    • System or security property
    • JDK

      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>http.keepAlive.time.server</B> and
          <B>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>

            dhanalla Dhamoder Nalla
            michaelm Michael McMahon
            Joe Darcy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: