summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas <>2023-11-29 09:46:07 +0100
committerThomas <>2023-11-29 09:46:07 +0100
commitb96944f03d573187a8ec94293124d7632d86e54d (patch)
tree3f37b6510bbbed9c0ae2c45ef93107851878f683
parent7dc56d353fcd5c76d9be3660bbdd2cb4a8b23f38 (diff)
downloadEAAF-Components-b96944f03d573187a8ec94293124d7632d86e54d.tar.gz
EAAF-Components-b96944f03d573187a8ec94293124d7632d86e54d.tar.bz2
EAAF-Components-b96944f03d573187a8ec94293124d7632d86e54d.zip
fix(http): update HTTP client factory to fix problem with open 'idle-connection-evictor' threads
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientFactory.java12
1 files 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<String, Pair<HttpClientBuilder, HttpClientConnectionManager>> 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());