From b96944f03d573187a8ec94293124d7632d86e54d Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Wed, 29 Nov 2023 09:46:07 +0100 Subject: fix(http): update HTTP client factory to fix problem with open 'idle-connection-evictor' threads --- .../at/gv/egiz/eaaf/core/impl/http/HttpClientFactory.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientFactory.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientFactory.java index a96c64e3..5e8edfa3 100644 --- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientFactory.java +++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientFactory.java @@ -36,6 +36,7 @@ import org.apache.hc.core5.http.config.Registry; import org.apache.hc.core5.http.config.RegistryBuilder; import org.apache.hc.core5.http.io.SocketConfig; import org.apache.hc.core5.http.protocol.HttpContext; +import org.apache.hc.core5.pool.PoolConcurrencyPolicy; import org.apache.hc.core5.ssl.SSLContexts; import org.apache.hc.core5.util.TimeValue; import org.springframework.beans.factory.annotation.Autowired; @@ -103,6 +104,9 @@ public class HttpClientFactory implements IHttpClientFactory { public static final int DEFAULT_CLEANUP_RUNNER_TIME = 30000; public static final int DEFAULT_CLEANUP_IDLE_TIME = 60; + public static final TimeValue CLEANUP_IDLE_TIME = + TimeValue.of(DEFAULT_CLEANUP_IDLE_TIME, TimeUnit.SECONDS); + private String defaultConfigurationId = null; private final Map> availableBuilders = new HashMap<>(); @@ -155,8 +159,8 @@ public class HttpClientFactory implements IHttpClientFactory { sslConnectionFactory); // set evication for connection pool - builder.evictExpiredConnections(); - builder.evictIdleConnections(TimeValue.ofSeconds(DEFAULT_CLEANUP_IDLE_TIME)); + // builder.evictExpiredConnections(); + // builder.evictIdleConnections(TimeValue.ofSeconds(DEFAULT_CLEANUP_IDLE_TIME)); // set interceptor if (config.getMessageInterceptors() != null) { @@ -340,7 +344,8 @@ public class HttpClientFactory implements IHttpClientFactory { if (basicConfig.getBasicConfigurationBoolean(PROP_CONFIG_CLIENT_HTTP_CONNECTION_POOL_USE, true)) { final PoolingHttpClientConnectionManager connectionPool = new PoolingHttpClientConnectionManager( - getDefaultRegistry(sslConnectionFactory)); + getDefaultRegistry(sslConnectionFactory), + PoolConcurrencyPolicy.STRICT, CLEANUP_IDLE_TIME, null); connectionPool.setDefaultMaxPerRoute(Integer.parseInt( basicConfig.getBasicConfiguration(PROP_CONFIG_CLIENT_HTTP_CONNECTION_POOL_MAXPERROUTE, DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_POOL_MAXPERROUTE))); @@ -359,6 +364,7 @@ public class HttpClientFactory implements IHttpClientFactory { DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_CONNECTION)), TimeUnit.SECONDS) .build()); + builder.setConnectionManager(connectionPool); log.debug("Initalize http-client pool with, maxTotal: {} maxPerRoute: {}", connectionPool.getMaxTotal(), connectionPool.getDefaultMaxPerRoute()); -- cgit v1.2.3