[OLINGO-1344] Fix deadlock ThreadPool (by Aleksandr)

This commit is contained in:
mibo 2019-04-26 20:15:36 +02:00
parent 50dec8d5d2
commit 482c99c9f0
1 changed files with 19 additions and 6 deletions

View File

@ -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<String, Object> CONF = new HashMap<String, Object>();
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<Runnable>());
tp.allowCoreThreadTimeOut(true);
return tp;
}
/**
* Gets given configuration property.