Improve thread-pool-settings for the WebServer

This commit is contained in:
Blue (Lukas Rieger) 2021-04-02 13:18:33 +02:00
parent 5a342e1fe0
commit ad809600b6
No known key found for this signature in database
GPG Key ID: 904C4995F9E1F800

View File

@ -31,10 +31,7 @@
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
public class WebServer extends Thread {
@ -68,8 +65,7 @@ public WebServer(InetAddress bindAddress, int port, int maxConnections, HttpRequ
public synchronized void start() {
close();
connectionThreads = new ThreadPoolExecutor(maxConnections, maxConnections, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
connectionThreads.allowCoreThreadTimeOut(true);
connectionThreads = new ThreadPoolExecutor(Math.min(maxConnections, 8), maxConnections, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
try {
server = new ServerSocket(port, maxConnections, bindAddress);