<div dir="ltr">Hi,<div>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.</div><div><br></div><div>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.</div>
<div>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?</div><div><br></div><div>Bellow is the example source:</div>
<div><br></div><div><div>import javax.servlet.ServletConfig;<br></div><div>import javax.servlet.ServletException;</div><div>import javax.servlet.http.HttpServlet;</div><div>import javax.servlet.http.HttpServletRequest;</div>
<div>import javax.servlet.http.HttpServletResponse;</div><div><br></div><div>import io.undertow.Handlers;</div><div>import io.undertow.Undertow;</div><div>import io.undertow.server.HttpHandler;</div><div>import io.undertow.server.handlers.PathHandler;</div>
<div>import io.undertow.servlet.api.DeploymentInfo;</div><div>import io.undertow.servlet.api.DeploymentManager;</div><div><br></div><div>import java.io.IOException;</div><div>import java.io.PrintWriter;</div><div><br></div>
<div>import static io.undertow.servlet.Servlets.defaultContainer;</div><div>import static io.undertow.servlet.Servlets.deployment;</div><div>import static io.undertow.servlet.Servlets.servlet;</div><div><br></div><div>public class TestServer {</div>
<div> public static class TestServlet extends HttpServlet {</div><div> @Override</div><div> public void init(final ServletConfig config) throws ServletException {</div><div> super.init(config);</div>
<div> }</div><div><br></div><div> @Override</div><div> protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {</div><div> try {</div>
<div> Thread.sleep(5000);</div><div> } catch (InterruptedException e) {</div><div> e.printStackTrace();</div><div> }</div><div> PrintWriter writer = resp.getWriter();</div>
<div> writer.write("Done!");</div><div> writer.close();</div><div> }</div><div><br></div><div> @Override</div><div> protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {</div>
<div> doGet(req, resp);</div><div> }</div><div> }</div><div><br></div><div> public static void main(String[] args) {</div><div> try {</div><div> String context = "/";</div>
<div> DeploymentInfo servletBuilder = deployment()</div><div> .setClassLoader(TestServer.class.getClassLoader())</div><div> .setContextPath(context)</div><div> .setDeploymentName("test.war")</div>
<div> .addServlets(</div><div> servlet("TestServlet", TestServer.TestServlet.class)</div><div> .addMapping("/*"));</div>
<div><br></div><div> DeploymentManager manager = defaultContainer().addDeployment(servletBuilder);</div><div> manager.deploy();</div><div><br></div><div> HttpHandler servletHandler = manager.start();</div>
<div> PathHandler path = Handlers.path(Handlers.redirect(context))</div><div> .addPrefixPath(context, servletHandler);</div><div> Undertow server = Undertow.builder()</div><div> .addHttpListener(8181, "0.0.0.0")</div>
<div> .setHandler(path)</div><div> .build();</div><div> server.start();</div><div> } catch (ServletException e) {</div><div> throw new RuntimeException(e);</div>
<div> }</div><div> }</div><div>}</div></div><div><br></div></div>