Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is Jersey's @ManagedAsync annotation?

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.

like image 274
akonsu Avatar asked Nov 18 '16 15:11

akonsu


1 Answers

@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

like image 97
Vikas Sachdeva Avatar answered Oct 20 '22 23:10

Vikas Sachdeva