[undertow-dev] Who Needs JAX-RS...

Miere Teixeira miere.teixeira at gmail.com
Mon Aug 31 20:28:06 EDT 2015


Steve,

At my first look, I felt like you were facing the issue that Peter have
pointed out.
Taking a deeper look into your code, I found out what you have explained on
your last email (line 47 of your source code).
You are right, it seems that you aren't blocking your IO threads.

Just keep in mind that it will always dispatch your request into a Worker
thread. By design, HttpHandler could be nested in a chain of handlers, and
some built in HttpHandlers will dispatch your request into a Worker thread
(as AuthenticationCallHandler, per example). Thus, if you plan to wrap your
requests with such handlers all of your requests will be dispatched into
Worker threads twice per request. To avoid this, you should apply the fix
that Peter have suggested already.

Regards,
Miere


On Mon, Aug 31, 2015 at 1:08 PM Steve Logue <bitvector2 at gmail.com> wrote:

> Thanks for looking - how does it look now?  This is actually what I had
> beforehand at some point.  Now it uses a lambda statement to dispatch to
> the handler method on a worker thread.
>
> -STEVEl
>
>
> On Mon, Aug 31, 2015 at 5:40 AM, peter royal <peter.royal at pobox.com>
> wrote:
>
>> You are blocking the IO thread in each of your handlers.
>>
>>
>>
>> When each handler is a class, you can do:
>>
>>
>>
>> if( exchange.isInIoThread()) {
>>
>>   exchange.dispatch(this);
>>
>>   return;
>>
>> }
>>
>>
>>
>> but since you are using lambda's, that won't work. In this case, you
>> might want to just pass a Runnable to exchange.dispatch()
>>
>>
>>
>> that will put you on a worker pool thread where it is safe to block on
>> the Await.result call.
>>
>>
>>
>> an alternate (but lacking the timeout option) method I use is to leverage
>> the JDK8 CompletableFuture and use .thenAccept / .exceptionally to return
>> the response when available.
>>
>>
>>
>> -pete
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On 2015-08-29 21:00, Steve Logue wrote:
>>
>> Hi Folks, I'm definitely new to Undertow and super impressed with it.
>> However the docs are a bit thin in regards to using the RoutingHandler and
>> doing full async processing.  May I ask for a quick check of my approach to
>> using Undertow and trying not to block anywhere:
>>
>>
>> https://github.com/bitvector2/microservice2/blob/master/src/main/java/org/bitvector/microservice2/HttpActor.java
>>
>> -STEVEl
>>
>>
>> --
>>
>> http://www.bitvector.org/
>>
>> _______________________________________________
>> undertow-dev mailing list
>> undertow-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/undertow-dev
>>
>>
>> --
>> (peter.royal|osi)@pobox.com - http://fotap.org/~osi
>>
>
>
>
> --
>
> http://www.bitvector.org/
> _______________________________________________
> undertow-dev mailing list
> undertow-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/undertow-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20150901/50f9f15e/attachment.html 


More information about the undertow-dev mailing list