Would anyone please explain the meaning of the @ManagedAsync
annotation? What does it do?
From the documentation (https://jersey.java.net/apidocs/2.21/jersey/org/glassfish/jersey/server/ManagedAsync.html):
Indicates that the resource method to which the annotation has been applied should be executed on a separate thread managed by an internal Jersey executor service.
Are not resources executed on separate threads anyway? I am confused.
@ManagedAsync is used for making a jersey resource asynchronous. It means that complete resource execution is done in another thread, not in the main thread in which request is received.
There are 2 ways for making asynchronous jersey resource -
1) Using @Suspended on AsyncResponse asyncResponse - But in this case, you have to create your own thread in code and execute expensive task in that thread.
2) Using @ManagedAsync - In this case, there is no need to create new thread manually, jersey creates thread and execute resource method in that thread.
More information can be found at Async Rest
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With