How can I change thread pool size in embedded Jetty 9? Do we need any specific component for this?
Asked
Active
Viewed 5.0k times
2 Answers
31
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);

rocketboy
- 9,573
- 2
- 34
- 36
-
6Your 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. – Alexander Bezrodniy Aug 30 '13 at 13:37
-
6ThreadPool can be passed in on the constructor of the Server instance, or just call server.getThreadPool() and tweak that before calling .start() – jesse mcconnell Aug 30 '13 at 13:42
-
1In 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. – rocketboy Aug 30 '13 at 13:58
-
3But how to set port at the same time? – Bin Wang Nov 13 '14 at 07:32
-
Note this XML will not work in later releases Jetty 9 -- I am using 9.2.3. sprynter's answer works. – Eric Dec 08 '14 at 18:13
-
1@BinWang I'm using `http=new ServerConnector...` then `http.setPort` and `server.setConnectors(new Connector[]{http});` – Karussell Oct 23 '16 at 18:53
21
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>
...

sprynter
- 339
- 2
- 5
-
1Will this method work for Jetty HTTP Client? Where does the file go in JAR file for an embedded client? – will Sep 01 '14 at 05:39
-
This is the only thing I found on the internet that works. I'm using the Jetty Maven plugin v9.2.2. Thanks!! – Cameron Sep 19 '14 at 15:59