Change thread pool size in Jetty 9
45,687
Solution 1
From docs:
The Server instance provides a ThreadPool instance that is the default Executor service other Jetty server components use. The prime configuration of the thread pool is the maximum and minimum size and is set in etc/jetty.xml.
<Configure id="server" class="org.eclipse.jetty.server.Server">
<Set name="threadPool">
<New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
<Set name="minThreads">10</Set>
<Set name="maxThreads">1000</Set>
</New>
</Set>
</Configure>
Or
QueuedThreadPool threadPool = new QueuedThreadPool(100, 10);
Server server = new Server(threadPool);
Solution 2
As noted, and corrected in the Java code example above, the threadpool is now provided as a constructor argument in Jetty 9 (and later).
The corrected XML example:
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- =========================================================== -->
<!-- Configure the Server Thread Pool. -->
<!-- -->
<!-- Consult the javadoc of o.e.j.util.thread.QueuedThreadPool -->
<!-- for all configuration that may be set here. -->
<!-- =========================================================== -->
<Get name="ThreadPool">
<Set name="minThreads" type="int">10</Set>
<Set name="maxThreads" type="int">200</Set>
<Set name="idleTimeout" type="int">60000</Set>
<Set name="detailedDump">false</Set>
</Get>
...
Related videos on Youtube
Author by
Alexander Bezrodniy
Updated on July 19, 2020Comments
-
Alexander Bezrodniy almost 4 years
How can I change thread pool size in embedded Jetty 9? Do we need any specific component for this?
-
Alexander Bezrodniy almost 11 yearsYour code sample doesn't work for Jetty 9.04, as there are no setThreadPool method in Server class. Also, I need such preference for embedded jetty server, I've updated a question.
-
jesse mcconnell almost 11 yearsThreadPool can be passed in on the constructor of the Server instance, or just call server.getThreadPool() and tweak that before calling .start()
-
rocketboy almost 11 yearsIn Jetty-9 many of the method signatures have changed for server. Instead of getters and setters, it is more constructor based now. Also, fixed the code sample.
-
will almost 10 yearsWill this method work for Jetty HTTP Client? Where does the file go in JAR file for an embedded client?
-
Cameron almost 10 yearsThis is the only thing I found on the internet that works. I'm using the Jetty Maven plugin v9.2.2. Thanks!!
-
Bin Wang over 9 yearsBut how to set port at the same time?
-
Eric over 9 yearsNote this XML will not work in later releases Jetty 9 -- I am using 9.2.3. sprynter's answer works.
-
Karussell over 7 years@BinWang I'm using
http=new ServerConnector...
thenhttp.setPort
andserver.setConnectors(new Connector[]{http});