<div dir="ltr"><div class="gmail_default" style="font-family:'comic sans ms',sans-serif"><div style="font-family:arial,sans-serif;font-size:13px">Hello guys,</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px">could you help me a little bit with Undertow? </div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
I follow all instructions in Undertown's poor documentation. So here is the class :</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">public class HelloWorldServer {</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px"> public static void main(String... args) {</div><div style="font-family:arial,sans-serif;font-size:13px">
Undertow server = Undertow.builder()</div><div style="font-family:arial,sans-serif;font-size:13px"> .addHttpListener(8080, "localhost")</div><div style="font-family:arial,sans-serif;font-size:13px">
.setHandler(new HttpHandler() {</div><div style="font-family:arial,sans-serif;font-size:13px"> @Override</div><div style="font-family:arial,sans-serif;font-size:13px"> public void handleRequest(final HttpServerExchange exchange) throws Exception {</div>
<div style="font-family:arial,sans-serif;font-size:13px"> if (exchange.isInIoThread()) {</div><div style="font-family:arial,sans-serif;font-size:13px"> System.out.println("Thread #" + Thread.currentThread().getName() + " is I/O : handle this");</div>
<div style="font-family:arial,sans-serif;font-size:13px"> exchange.dispatch(this);</div><div style="font-family:arial,sans-serif;font-size:13px"> return;</div><div style="font-family:arial,sans-serif;font-size:13px">
}</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px"> //[1]</div><div style="font-family:arial,sans-serif;font-size:13px">
System.out.println("Thread #" + Thread.currentThread().getName() + " Start waiting");</div><div style="font-family:arial,sans-serif;font-size:13px"> Thread.sleep(15000);</div>
<div style="font-family:arial,sans-serif;font-size:13px"> System.out.println("Thread #" + Thread.currentThread().getName() + " Finish waiting");</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px"> System.out.println();</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");</div><div style="font-family:arial,sans-serif;font-size:13px"> exchange.getResponseSender().send("Hello world from thread " + Thread.currentThread().getId());</div>
<div style="font-family:arial,sans-serif;font-size:13px"> //[2]</div><div style="font-family:arial,sans-serif;font-size:13px"> }</div><div style="font-family:arial,sans-serif;font-size:13px">
}).build();</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px"> server.start();</div><div style="font-family:arial,sans-serif;font-size:13px">
}</div><div style="font-family:arial,sans-serif;font-size:13px">}</div><div style="font-family:arial,sans-serif;font-size:13px"> </div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
When I start it and make three http get request simultaneously I can see this output in console :</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
<div>Thread #XNIO-1 I/O-1 is I/O : handle this</div><div>Thread #XNIO-1 task-1 Start waiting</div><div>Thread #XNIO-1 task-1 Finish waiting</div><div><br></div><div>Thread #XNIO-1 I/O-1 is I/O : handle this</div><div>Thread #XNIO-1 task-2 Start waiting</div>
<div>Thread #XNIO-1 task-2 Finish waiting</div><div><br></div><div>Thread #XNIO-1 I/O-1 is I/O : handle this</div><div>Thread #XNIO-1 task-3 Start waiting</div><div>Thread #XNIO-1 task-3 Finish waiting</div></div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">I think that code beetween //[1] and //[2] should perform in separate thread (and as we can see from the console it really does), but why the main I/O thread are waiting and does not handle other requests?</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">So if my code is correct than it means that Undertow could handle one request in time...</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px">What I do wrong?</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div></div><div>Best,<br>Mikhail</div>
</div>