Hi,
I did some testing with servlet deployment on undertow and it seems that
servlet requests are always executed on IO thread instead of dispatched to
worker threads.
Basically I used modified servlet example from undertow github (I just
added Thread.sleep(5000) to servlet). When I send request simultaneously
from two browser tabs, first request is retrieved after 5 seconds as
expected, but the second after 10 seconds, which means that IO thread was
blocked until first request was completed.
Is there some configuration parameter in DeploymentInfo which forces
request to be dispatched to worker threads, or is there some other way to
prevent IO thread from blocking?
Bellow is the example source:
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import io.undertow.Handlers;
import io.undertow.Undertow;
import io.undertow.server.HttpHandler;
import io.undertow.server.handlers.PathHandler;
import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.DeploymentManager;
import java.io.IOException;
import java.io.PrintWriter;
import static io.undertow.servlet.Servlets.defaultContainer;
import static io.undertow.servlet.Servlets.deployment;
import static io.undertow.servlet.Servlets.servlet;
public class TestServer {
public static class TestServlet extends HttpServlet {
@Override
public void init(final ServletConfig config) throws
ServletException {
super.init(config);
}
@Override
protected void doGet(final HttpServletRequest req, final
HttpServletResponse resp) throws ServletException, IOException {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
PrintWriter writer = resp.getWriter();
writer.write("Done!");
writer.close();
}
@Override
protected void doPost(final HttpServletRequest req, final
HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
public static void main(String[] args) {
try {
String context = "/";
DeploymentInfo servletBuilder = deployment()
.setClassLoader(TestServer.class.getClassLoader())
.setContextPath(context)
.setDeploymentName("test.war")
.addServlets(
servlet("TestServlet",
TestServer.TestServlet.class)
.addMapping("/*"));
DeploymentManager manager =
defaultContainer().addDeployment(servletBuilder);
manager.deploy();
HttpHandler servletHandler = manager.start();
PathHandler path = Handlers.path(Handlers.redirect(context))
.addPrefixPath(context, servletHandler);
Undertow server = Undertow.builder()
.addHttpListener(8181, "0.0.0.0")
.setHandler(path)
.build();
server.start();
} catch (ServletException e) {
throw new RuntimeException(e);
}
}
}