Ok, I think my mail could be reduced to :<br><br><div>Is it possible possible to transfer the <span style="font-size:13.1999998092651px;line-height:19.7999992370605px">HttpServerExchange </span>responsibility<span style="font-size:13.1999998092651px;line-height:19.7999992370605px"> to another thread ?</span></div><div><span style="font-size:13.1999998092651px;line-height:19.7999992370605px"><br></span></div><div>Regards</div><div>Laurent</div><div><div><br></div></div><br><div class="gmail_quote">On Fri Dec 12 2014 at 7:11:01 PM Laurent Bedubourg &lt;<a href="mailto:laurent@labe.me">laurent@labe.me</a>&gt; wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<div><br></div><div>I am evaluating Undertow and trying to fit an async database (with scala, Activate and <a href="https://github.com/mauricio/postgresql-async" target="_blank">https://github.com/mauricio/postgresql-async</a> which use netty and nio).</div><div><br></div><div>The good news is that it more or less works.</div><div><br></div><div>My main concern is that the database system create threads using scala futures and that <span style="font-size:13.1999998092651px">I am forced to &quot;Await&quot; for the result of my Futures to send the result to the HttpServerExchange.</span></div><div><span style="font-size:13.1999998092651px"><br></span></div><div>I am forced to dispath() the request because Await locks the current thread and I shouldn&#39;t lock the IO thread from my Handler, should I?</div><div><br></div><div><span style="font-size:13.1999998092651px">It made me wondering : is is really a good idea to use futures + Await with undertow and more generaly nio? </span><br></div><div><br></div><div>If the thread pool is limited and I lock threads, even if the database driver is async and uses nio, am I bitting my own leg?</div><div><br></div><div>Thanks for any input you can give me and sorry if it&#39;s too scala related :)</div><div><br></div><div>Regards</div><div>Laurent</div><div><br></div><div>PS: Here&#39;s the handleRequest I am using to test this, any comment or help welcome too since I am discovering the API.</div><div><br></div><div><div>def handleRequest(x:io.undertow.server.HttpServerExchange){</div><div>  if (x.isInIoThread()){</div><div>    x.dispatch(this)</div><div>    return</div><div>  }</div><div>  // useful or not? no change</div><div>  // x.startBlocking()</div><div><br></div><div>  // Ok, we are in worker thread we can work a little with database</div><div>  // val f = asyncTransactionalChain { implicit context =&gt;</div><div>  //   for (</div><div>  //     a &lt;- asyncTransactional { new AMember(&quot;aaa&quot;) };</div><div>  //     b &lt;- asyncById[AMember](<a href="http://a.id" target="_blank">a.id</a>)</div><div>  //   ) yield b</div><div>  // }</div><div><br></div><div>  // Simulate database work with just a future</div><div>  val f = future {</div><div>    Some(1)</div><div>  }(scala.concurrent.ExecutionContext.Implicits.global)</div><div><br></div><div>  // send string to xchange</div><div>  def sendReply(str:String){</div><div>    x.getResponseHeaders().put(io.undertow.util.Headers.CONTENT_TYPE, &quot;text/plain&quot;)</div><div>    x.getResponseSender().send(str)</div><div>    // x.endExchange()</div><div>  }</div><div><br></div><div>  // // this fails</div><div>  // f.onSuccess {</div><div>  //   case Some(result) =&gt; sendReply(result.toString)</div><div>  // }(scala.concurrent.ExecutionContext.Implicits.global)</div><div><br></div><div>  // // this works</div><div>  val result = Await.result(f, Duration(1000, MILLISECONDS))</div><div>  sendReply(result.toString)</div><div>}</div></div><div><br></div></blockquote></div>