App Http Client Timeout Configuration

Default timeouts available via GsiHttpClientUtils

  • httpConnectTimeout
  • httpReadWriteTimeout

Values are defined in our configuration files:


  • Connection timeout: time to wait until the other side answers our connection request on a low level. Connection timeout could mean there is a network problem or the request dropped along the way or the server system is completely unresponsive.
  • Read / Write timeout: time to keep the low level (socket) connection open even if no data is received / sent. This can depend highly on your application or performed action. A timeout could mean that the service is non responsive anymore or the service has too much load. But be aware it could also just mean that a request takes a long time to process.
    • You usually don't want to cancel requests just because they take too long to answer so these timeouts might need adjustment based on the use case. On the other hand you don't want to cause a congestion in case of a high load situation with inefficient requests. This way they could be detected and optimized.
    • In case of long running connections, like Server Sent Events (SSE) connections, the server should send a heart beat message to keep the connection alive or maybe disable the timeout if this is not applicable.

Timeout configuration examples

Java HttpURLConnection (URL Object)

Configured by central properties and You just have to make sure that our are loaded on application start before making any network calls. These config settings are already in place since a couple of releases.

If you are using the Java Fx GSI Application Base class this is done automatically for you.


Java HttpClient 11

HttpClient client = HttpClient.newBuilder() //
        .connectTimeout(GsiHttpClientUtils.httpConnectTimeout()) //

HttpRequest request = HttpRequest.newBuilder() //
        .uri(URI.create("")) //
        .timeout(GsiHttpClientUtils.httpReadWriteTimeout()) //
        .GET() //

HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
System.out.println(response.body().substring(0, 512));

Apache httpcomponents-client 4.5

RequestConfig.Builder requestConfigBuilder = RequestConfig.custom() //
        .setConnectTimeout(GsiHttpClientUtils.httpConnectTimeoutMs()) //
        .setConnectionRequestTimeout(GsiHttpClientUtils.httpConnectTimeoutMs()) //

return HttpClients.custom() //
        .setDefaultRequestConfig( //

HttpGet httpGet = new HttpGet(url);
// httpGet.setConfig(requestConfig); // alternative to setting it centrally or to overwrite it
CloseableHttpResponse response = httpClient.execute(httpGet);
try {
    System.out.println(EntityUtils.toString(response.getEntity()).substring(0, 512));
} finally {
    httpClient.close(); // on app/service shutdown
  • If not set: Timeouts: "Default: -1. A timeout value of zero is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default if applicable)."
  • So the default is quite vague, the following seems reasonable The default read timeout is infinity on all platforms. "The default connect timeout is of the order of a minute, but it varies by platform."

Spring RestTemplate

Depends on the used client, it defaults to Java HttpURLConnection, see above.

For details on how to configure one or the other HTTP Client:
  • If not set: Timeout: Depends on the used client
  • Note: Spring RestTemplate is in maintainance mode and not actively developed anymore by Spring

OkHttp 3.6.0 / 4.9.2

OkHttpClient client = new OkHttpClient.Builder() //
        .connectTimeout(GsiHttpClientUtils.httpConnectTimeoutMs(), TimeUnit.MILLISECONDS) //
        .readTimeout(GsiHttpClientUtils.httpReadWriteTimeoutMs(), TimeUnit.MILLISECONDS) //
        .writeTimeout(GsiHttpClientUtils.httpReadWriteTimeoutMs(), TimeUnit.MILLISECONDS) //

Request request = new Request.Builder() //
        .url("") //

try (Response response = client.newCall(request).execute()) {
    System.out.println(response.body().string().substring(0, 512));
  • If not set: The default value for connect, read, write is 10 seconds

More information


-- BenjaminPeter - 08 Nov 2021
Topic revision: r3 - 09 Nov 2021, BenjaminPeter
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback