jsr339-experts@jax-rs-spec.java.net

[jsr339-experts] Re: Overhead of AsyncResponse

From: Jan Algermissen <jan.algermissen_at_nordsc.com>
Date: Thu, 8 Nov 2012 23:59:07 +0100

On Nov 7, 2012, at 5:50 PM, Jan Algermissen <jan.algermissen_at_nordsc.com> wrote:

> Hi,
>
> do you have an estimate what the overhead of using an AsyncResponse is, if you send back a sync. response for the majority of cases?
>
> Use Case:
>
> Implement a resource method that retains the opportunity for handling a request asynchronously but decides thatonly when the method is actually invoked. IOW, when the method determines that a synchronous response is fine, it simply invokes the async response right away.

Found a better solution:

Use a resource method and conditionally 'route' to subresource locators, one doing a sync response the other one using AsyncResponse.

@Path("large-thing")
public I_LargeThing getLargeThing() {
        
        // If preparing the large thing would block thread, use the async version...
        if( large thing is not ready yet) {
                return new LargeThingPreparer();
        }

        return new LargeThing();
}


Jan











>
> Does that significanly affect performance or resource usage?
>
> Jan
>
>