How do you set both port and thread pool using embedded jetty, v 9.1.0

情到浓时终转凉″ 提交于 2019-12-21 07:59:32

问题


I'm using jetty 9.1.0, embedded, and would like to set both port and ThreadPool. I see a constructor for each, but don't see how to use one of those, and then any way to set the other.

doing this

Server server = new Server(9090);

or

Server server = new Server(new QueuedThreadPool(100, 10));

but there's no setPort or setThreadPool on Server.


回答1:


QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(500);

Server server = new Server(threadPool);

ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config));
http.setPort(81);

server.addConnector(http);



回答2:


I can't test it right know, but I assume you can

a) Use a configuration file and load it

or

b) Use the QueuedThreadPool and do the following:

 SelectChannelConnector connector = new SelectChannelConnector();
 connector.setPort(9090);
 server.addConnector(connector);



回答3:


    Server server = new Server(new QueuedThreadPool(128, 8));
    ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory());

    connector.setPort(8897);
    server.addConnector(connector);



回答4:


You could go with XML configuration from /etc/jetty.xml file, which is well documented and also use beans with Spring configuration.

There's no constructor that will take ThreadPool and port together.



来源:https://stackoverflow.com/questions/23329135/how-do-you-set-both-port-and-thread-pool-using-embedded-jetty-v-9-1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!