Skip to content

Commit

Permalink
set allowCoreThreadTimeOut for the ThreadPool, closeable
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsbehlen committed Mar 4, 2024
1 parent 0e15cd6 commit 1e0ec02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/privacyidea/Endpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/org/privacyidea/PrivacyIDEA.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.privacyidea;

import java.io.Closeable;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
Expand All @@ -26,7 +28,6 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -54,15 +55,15 @@
* This is the main class. It implements the common endpoints such as /validate/check as methods for easy usage.
* To create an instance of this class, use the nested PrivacyIDEA.Builder class.
*/
public class PrivacyIDEA
public class PrivacyIDEA implements Closeable
{
private final PIConfig configuration;
private final IPILogger log;
private final IPISimpleLogger simpleLog;
private final Endpoint endpoint;
// Thread pool for connections
private final BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(100);
private final ExecutorService threadPool = new ThreadPoolExecutor(20, 20, 10, TimeUnit.SECONDS, queue);
private final BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(1000);
private final ThreadPoolExecutor threadPool = new ThreadPoolExecutor(20, 20, 10, TimeUnit.SECONDS, queue);
final JSONParser parser;
// Responses from these endpoints will not be logged. The list can be overwritten.
private List<String> logExcludedEndpoints = Arrays.asList(PIConstants.ENDPOINT_AUTH,
Expand All @@ -75,6 +76,7 @@ private PrivacyIDEA(PIConfig configuration, IPILogger logger, IPISimpleLogger si
this.configuration = configuration;
this.endpoint = new Endpoint(this);
this.parser = new JSONParser(this);
this.threadPool.allowCoreThreadTimeOut(true);
}

/**
Expand Down Expand Up @@ -535,6 +537,12 @@ else if (this.simpleLog != null)
}
}

@Override
public void close() throws IOException
{
this.threadPool.shutdown();
}

/**
* Get a new Builder to create a PrivacyIDEA instance.
*
Expand Down

0 comments on commit 1e0ec02

Please sign in to comment.