<div dir="ltr"><div class="gmail_default" style="font-family:&#39;comic sans ms&#39;,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&#39;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, &quot;localhost&quot;)</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(&quot;Thread #&quot; + Thread.currentThread().getName() + &quot; is I/O : handle this&quot;);</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(&quot;Thread #&quot; + Thread.currentThread().getName() + &quot; Start waiting&quot;);</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(&quot;Thread #&quot; + Thread.currentThread().getName() + &quot; Finish waiting&quot;);</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, &quot;text/plain&quot;);</div><div style="font-family:arial,sans-serif;font-size:13px">                        exchange.getResponseSender().send(&quot;Hello world from thread &quot; + 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>