[undertow-dev] what I do wrong?
Mikhail Tyamin
mikhail.tiamine at gmail.com
Mon Feb 17 04:33:41 EST 2014
Hello guys,
could you help me a little bit with Undertow?
I follow all instructions in Undertown's poor documentation. So here is the
class :
public class HelloWorldServer {
public static void main(String... args) {
Undertow server = Undertow.builder()
.addHttpListener(8080, "localhost")
.setHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange
exchange) throws Exception {
if (exchange.isInIoThread()) {
System.out.println("Thread #" +
Thread.currentThread().getName() + " is I/O : handle this");
exchange.dispatch(this);
return;
}
//[1]
System.out.println("Thread #" +
Thread.currentThread().getName() + " Start waiting");
Thread.sleep(15000);
System.out.println("Thread #" +
Thread.currentThread().getName() + " Finish waiting");
System.out.println();
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("Hello world from
thread " + Thread.currentThread().getId());
//[2]
}
}).build();
server.start();
}
}
When I start it and make three http get request simultaneously I can see
this output in console :
Thread #XNIO-1 I/O-1 is I/O : handle this
Thread #XNIO-1 task-1 Start waiting
Thread #XNIO-1 task-1 Finish waiting
Thread #XNIO-1 I/O-1 is I/O : handle this
Thread #XNIO-1 task-2 Start waiting
Thread #XNIO-1 task-2 Finish waiting
Thread #XNIO-1 I/O-1 is I/O : handle this
Thread #XNIO-1 task-3 Start waiting
Thread #XNIO-1 task-3 Finish waiting
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?
So if my code is correct than it means that Undertow could handle one
request in time...
What I do wrong?
Best,
Mikhail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20140217/44cca887/attachment.html
More information about the undertow-dev
mailing list