From 482c99c9f0c1f8ac9cd833285ef2dc3a8c2af180 Mon Sep 17 00:00:00 2001 From: mibo Date: Fri, 26 Apr 2019 20:15:36 +0200 Subject: [PATCH] [OLINGO-1344] Fix deadlock ThreadPool (by Aleksandr) --- .../olingo/client/core/ConfigurationImpl.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/ConfigurationImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/ConfigurationImpl.java index 14c59d6e8..9f88bdbf5 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/ConfigurationImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/ConfigurationImpl.java @@ -18,11 +18,6 @@ */ package org.apache.olingo.client.core; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - import org.apache.olingo.client.api.Configuration; import org.apache.olingo.client.api.http.HttpClientFactory; import org.apache.olingo.client.api.http.HttpUriRequestFactory; @@ -30,6 +25,13 @@ import org.apache.olingo.client.core.http.DefaultHttpClientFactory; import org.apache.olingo.client.core.http.DefaultHttpUriRequestFactory; import org.apache.olingo.commons.api.format.ContentType; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + public class ConfigurationImpl implements Configuration { private static final String DEFAULT_PUB_FORMAT = "pubFormat"; @@ -60,7 +62,18 @@ public class ConfigurationImpl implements Configuration { private final Map CONF = new HashMap(); - private transient ExecutorService executor = Executors.newFixedThreadPool(10); + private transient ExecutorService executor = createExecutor(10); + + private ExecutorService createExecutor(final int threads) { + final ThreadPoolExecutor tp = new ThreadPoolExecutor( + threads, + threads, + 5L, + TimeUnit.MILLISECONDS, + new LinkedBlockingQueue()); + tp.allowCoreThreadTimeOut(true); + return tp; + } /** * Gets given configuration property.