Java 在 Jetty 9 中更改线程池大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18534025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change thread pool size in Jetty 9
提问by Alexander Bezrodniy
How can I change thread pool size in embedded Jetty 9? Do we need any specific component for this?
如何在嵌入式 Jetty 9 中更改线程池大小?我们需要任何特定的组件吗?
采纳答案by rocketboy
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.
Server 实例提供了一个 ThreadPool 实例,它是其他 Jetty 服务器组件使用的默认 Executor 服务。线程池的主要配置是最大和最小大小,在 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);
回答by sprynter
As noted, and corrected in the Java code example above, the threadpool is now provided as a constructor argument in Jetty 9 (and later).
如前所述,并在上面的 Java 代码示例中进行了更正,线程池现在作为 Jetty 9(及更高版本)中的构造函数参数提供。
The corrected XML example:
更正的 XML 示例:
<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>
...