在Jetty 10中,`setQueue` 的等效方法是什么?

huangapple go评论74阅读模式
英文:

What is the equivalent method for setQueue in jetty 10?

问题

考虑设置setThreadPool()功能。

英文:

Was considering setThreadPool() functionality

答案1

得分: 1

QueuedThreadPool的构造函数有多种变体可以满足您的需求。

一般建议,如果在升级过程中找不到设置器,可以检查相同类的构造函数。另外,如果您使用了最新的Jetty 9.x版本,在构建过程中启用已弃用方法和类的报告,因为这些报告会提供关于需要在升级之前解决的代码的线索(检查相同类的javadoc以查找替代项)。

重要提示不要限制QueuedThreadPool的硬队列限制,否则会严重影响服务器性能和可扩展性。

传统上,在Jetty 6的时代,人们会尝试通过操纵线程来限制Jetty的功能,这种方法是有效的。

但是,在Jetty 7和Jetty 8的发展过程中,这变得不可行(可以感谢各种EE规范对此变化的贡献)。

到了Jetty 9时代,试图通过操纵线程池来影响行为已经不再可靠。

现在在Jetty 10上,通过操纵线程池来应用各种限制对Jetty的可靠性实际上是有害的。

但并非一无是处,自从Jetty 7以来,有许多现有且更好的技术可以限制Jetty的行为:请求、资源、连接、池等等。

另一种选择,如果您在乎的话,是不使用Jetty默认的QueuedThreadPool,而是使用标准的Java java.util.concurrent.ThreadPoolExecutor,并将其包装在org.eclipse.jetty.util.thread.ExecutorThreadPool中,然后将其传递给Jetty的new Server(ThreadPool)构造函数。这样做会失去Jetty内置的调试和转储功能,但它会工作。

英文:

The constructor of QueuedThreadPool has variations that can do what you need.

As a general tip, if you don't find a setter during your upgrade, check the constructor of the same class.
Also, if you used the latest Jetty 9.x version, enable the deprecated methods and classes reports during your build, as those give you clues on code that need to be resolved before you upgrade (check the javadoc for those same classes for replacements).

Important note: Do not limit QueuedThreadPool with a hard queue limit, you'll impact your server performance and scalability in horrible ways.

Traditionally, back in the Jetty 6 days people would attempt to limit what Jetty could do by manipulating the threading, which would work.

But over the course of Jetty 7 and Jetty 8 that became untenable (you can thank various EE specs for this change)

By the time Jetty 9 rolled around, attempting to influence behavior by manipulating the ThreadPool is no longer reliable.

Now on Jetty 10 it's actually harmful to reliability to manipulate the thread pool for applying various limits to Jetty.

But all is not lost, there are many existing (and better) techniques (since Jetty 7 days) to limit behaviors on Jetty: requests, resources, connections, pooling, etc

Another option, if you care, is to not use the Jetty default QueuedThreadPool, and just use a standard java java.util.concurrent.ThreadPoolExecutor wrapped with a org.eclipse.jetty.util.thread.ExecutorThreadPool that you pass to the Jetty new Server(ThreadPool) constructor. You'll lose debug and dump features built into Jetty, but it will work.

答案2

得分: -1

Server server = new Server();

HttpConfiguration httpConfig = new HttpConfiguration();
ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(httpConfig));

// 将最大队列大小设置为100
connector.setQueueCapacity(100);

server.setConnectors(new Connector[] { connector });

// 启动服务器
server.start();
英文:
Server server = new Server();

HttpConfiguration httpConfig = new HttpConfiguration();
ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(httpConfig));

// Set the maximum queue size to 100
connector.setQueueCapacity(100);

server.setConnectors(new Connector[] { connector });

// Start the server
server.start();

huangapple
  • 本文由 发表于 2023年4月7日 03:01:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75952897.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定