summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2023-02-14 14:52:02 +0100
committerSimon Rettberg2023-02-14 14:52:02 +0100
commite1d285db1f91abb3d65ac08d25a4f4fe44cffdcb (patch)
treeb380f8834a2cb00de0b00ed6a31cd24503091d3d
parentNanoHTTPD: Remove AsyncExecutor, move socket listen to constructor (diff)
downloadmaster-sync-shared-e1d285db1f91abb3d65ac08d25a4f4fe44cffdcb.tar.gz
master-sync-shared-e1d285db1f91abb3d65ac08d25a4f4fe44cffdcb.tar.xz
master-sync-shared-e1d285db1f91abb3d65ac08d25a4f4fe44cffdcb.zip
NanoHTTPD: Add constructor to easily set thread limit and queue len
-rw-r--r--src/main/java/fi/iki/elonen/NanoHTTPD.java19
1 files 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<Runnable>( 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<Runnable>( maxQueue ), new PrioThreadFactory( "httpd", Thread.NORM_PRIORITY ) ) );
}
/**