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

我与影子孤独终老i 提交于 2019-12-04 02:10:29
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);

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);
    Server server = new Server(new QueuedThreadPool(128, 8));
    ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory());

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

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.

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