我的服务器设置:
server = new Server(port);
ContextHandler testContext = new ContextHandler();
testContext.setContextPath("/test");
testContext.setHandler(new TestServlet());
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[]{ testContext});
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[]{ contexts, new DefaultHandler() });
server.setHandler(handlers);
server.setStopAtShutdown(true);
server.start();
测试代码:
public class TestServlet extends AbstractHandler
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
System.out.println("a");
try {
Thread.sleep(2500);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("b");
try {
Thread.sleep(2500);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("c");
try {
Thread.sleep(2500);
} catch (InterruptedException e) {
e.printStackTrace();
}
baseRequest.setHandled(true);
}
}
如果我访问
localhost/test
a
b
c
a
b
c
为什么这些请求没有并行处理?