From e1d285db1f91abb3d65ac08d25a4f4fe44cffdcb Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 14 Feb 2023 14:52:02 +0100 Subject: NanoHTTPD: Add constructor to easily set thread limit and queue len --- src/main/java/fi/iki/elonen/NanoHTTPD.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/fi/iki/elonen/NanoHTTPD.java b/src/main/java/fi/iki/elonen/NanoHTTPD.java index 610e15f..d3582fa 100644 --- a/src/main/java/fi/iki/elonen/NanoHTTPD.java +++ b/src/main/java/fi/iki/elonen/NanoHTTPD.java @@ -161,10 +161,25 @@ public abstract class NanoHTTPD implements Runnable this( null, port ); } + /** + * @param hostname Address to listen on + * @param port Port to listen on + */ public NanoHTTPD( String hostname, int port ) throws IOException { - this( hostname, port, new ThreadPoolExecutor( 2, 24, 1, TimeUnit.MINUTES, - new ArrayBlockingQueue( 16 ), new PrioThreadFactory( "httpd", Thread.NORM_PRIORITY ) ) ); + this( hostname, port, 24, 16 ); + } + + /** + * @param hostname Address to listen on + * @param port Port to listen on + * @param maxThreads Maximum number of threads to spawn before we start queuing requests + * @param maxQueue Maximum number of requests we queue before we start rejecting them with 503 + */ + public NanoHTTPD( String hostname, int port, int maxThreads, int maxQueue ) throws IOException + { + this( hostname, port, new ThreadPoolExecutor( 2, maxThreads, 1, TimeUnit.MINUTES, + new ArrayBlockingQueue( maxQueue ), new PrioThreadFactory( "httpd", Thread.NORM_PRIORITY ) ) ); } /** -- cgit v1.2.3-55-g7522