Skip to content

Commit 1e0ec02

Browse files
committed
set allowCoreThreadTimeOut for the ThreadPool, closeable
1 parent 0e15cd6 commit 1e0ec02

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/main/java/org/privacyidea/Endpoint.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.security.KeyManagementException;
2424
import java.security.NoSuchAlgorithmException;
2525
import java.util.Map;
26+
import java.util.concurrent.TimeUnit;
2627
import javax.net.ssl.SSLContext;
2728
import javax.net.ssl.SSLSocketFactory;
2829
import javax.net.ssl.TrustManager;

src/main/java/org/privacyidea/PrivacyIDEA.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.privacyidea;
1818

19+
import java.io.Closeable;
20+
import java.io.IOException;
1921
import java.util.Arrays;
2022
import java.util.Collections;
2123
import java.util.LinkedHashMap;
@@ -26,7 +28,6 @@
2628
import java.util.concurrent.BlockingQueue;
2729
import java.util.concurrent.Callable;
2830
import java.util.concurrent.ExecutionException;
29-
import java.util.concurrent.ExecutorService;
3031
import java.util.concurrent.Future;
3132
import java.util.concurrent.ThreadPoolExecutor;
3233
import java.util.concurrent.TimeUnit;
@@ -54,15 +55,15 @@
5455
* This is the main class. It implements the common endpoints such as /validate/check as methods for easy usage.
5556
* To create an instance of this class, use the nested PrivacyIDEA.Builder class.
5657
*/
57-
public class PrivacyIDEA
58+
public class PrivacyIDEA implements Closeable
5859
{
5960
private final PIConfig configuration;
6061
private final IPILogger log;
6162
private final IPISimpleLogger simpleLog;
6263
private final Endpoint endpoint;
6364
// Thread pool for connections
64-
private final BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(100);
65-
private final ExecutorService threadPool = new ThreadPoolExecutor(20, 20, 10, TimeUnit.SECONDS, queue);
65+
private final BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(1000);
66+
private final ThreadPoolExecutor threadPool = new ThreadPoolExecutor(20, 20, 10, TimeUnit.SECONDS, queue);
6667
final JSONParser parser;
6768
// Responses from these endpoints will not be logged. The list can be overwritten.
6869
private List<String> logExcludedEndpoints = Arrays.asList(PIConstants.ENDPOINT_AUTH,
@@ -75,6 +76,7 @@ private PrivacyIDEA(PIConfig configuration, IPILogger logger, IPISimpleLogger si
7576
this.configuration = configuration;
7677
this.endpoint = new Endpoint(this);
7778
this.parser = new JSONParser(this);
79+
this.threadPool.allowCoreThreadTimeOut(true);
7880
}
7981

8082
/**
@@ -535,6 +537,12 @@ else if (this.simpleLog != null)
535537
}
536538
}
537539

540+
@Override
541+
public void close() throws IOException
542+
{
543+
this.threadPool.shutdown();
544+
}
545+
538546
/**
539547
* Get a new Builder to create a PrivacyIDEA instance.
540548
*

0 commit comments

Comments
 (0)