[undertow-dev] what I do wrong?

Stuart Douglas sdouglas at redhat.com
Mon Feb 17 22:22:33 EST 2014


Are you sure the requests are actually being made simultaneously? That code should definitely work.

Stuart


----- Original Message -----
> From: "Mikhail Tyamin" <mikhail.tiamine at gmail.com>
> To: undertow-dev at lists.jboss.org
> Sent: Monday, 17 February, 2014 3:03:41 PM
> Subject: [undertow-dev] what I do wrong?
> 
> 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
> 
> _______________________________________________
> undertow-dev mailing list
> undertow-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/undertow-dev


More information about the undertow-dev mailing list