问题
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