Reputation: 5030
I'm using Jetty for the first time.
My server setup:
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();
Test code:
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);
}
}
If I visit localhost/test
on two different tabs, the 2nd request waits until first is finished, so my log looks like:
a
b
c
a
b
c
Why are they the requests not processed in parallel?
Upvotes: 2
Views: 1295
Reputation: 140447
It seems that people run into this from time to time (see here for example).
But as this nicely explains - jetty is built for serving users in parallel.
So the answer is: this is not a jetty problem - but a user error; for example by running the requests from a single browser (and that browser internally serializes the requests).
Upvotes: 2