问题
Please tell me, Is Jetty non-blocking web server by default or not?
For example, this code below runs Jetty as non-blocking web server?
Server server = new Server(8080);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
context.addServlet(new ServletHolder(new MyServlet()),"/*");
server.start();
server.join();
Thank you!!!
回答1:
It depends on which version of Jetty you're using.
- In Jetty 6, the "Server(int port)" constructor would open a blocking connector on that port.
- In Jetty 7, the "Server(int port)" constructor opens a non-blocking connector on that port.
If you really care about the behaviour, you're better off configuring the connector yourself, rather than relying on that convenience constructor.
来源:https://stackoverflow.com/questions/4156420/jetty-nonblocking-by-default