RestTemplate + ConnectionPoolTimeoutException: Timeout waiting for connection from pool

前端 未结 3 1140
野性不改
野性不改 2020-12-30 17:11

I got this error all of a sudden in production while the application was not under any load.

The issue happened when my code tries to send the PUT message using spri

3条回答
  •  心在旅途
    2020-12-30 17:19

    Caused by: org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool

    This error is self describing. You need to increase your connection pool in production - current implementation of HttpComponentsClientHttpRequestFactory default constructor is using HttpClientBuilder with .useSystemProperties().

    I believe it will be 5 connections by default. This works for client but is unlikely what you want in server environment. You need to use something like

    new RestTemplate(new HttpComponentsClientHttpRequestFactory(HttpClientBuilder.create()
                        .setMaxConnTotal(200)
                        .setMaxConnPerRoute(50)
                        .build()));
    

提交回复
热议问题