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>
    ...
Share:
45,687

Related videos on Youtube

Alexander Bezrodniy
Author by

Alexander Bezrodniy

Updated on July 19, 2020

Comments

  • Alexander Bezrodniy
    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
    Alexander Bezrodniy almost 11 years
    Your 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
    jesse mcconnell almost 11 years
    ThreadPool can be passed in on the constructor of the Server instance, or just call server.getThreadPool() and tweak that before calling .start()
  • rocketboy
    rocketboy almost 11 years
    In 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
    will almost 10 years
    Will this method work for Jetty HTTP Client? Where does the file go in JAR file for an embedded client?
  • Cameron
    Cameron almost 10 years
    This is the only thing I found on the internet that works. I'm using the Jetty Maven plugin v9.2.2. Thanks!!
  • Bin Wang
    Bin Wang over 9 years
    But how to set port at the same time?
  • Eric
    Eric over 9 years
    Note this XML will not work in later releases Jetty 9 -- I am using 9.2.3. sprynter's answer works.
  • Karussell
    Karussell over 7 years
    @BinWang I'm using http=new ServerConnector... then http.setPort and server.setConnectors(new Connector[]{http});