I have a long running Service method (doing business logic) and I would like the client to return immediately after submitting the request to the Controller. I would like the client to poll periodically to see if the Service method has completed execution.
After reading through these two links :
link1
link2
I am convinced that @Async is the right approach for my situation. My question is which, the Service method or the Controller method should have the @Async annotation. And how exactly will the Controller method have reference to a Future object so that it can invoke its get() or isDone() methods.
Add a comment
|
1 Answer
Put the @Async on a service method that calls the "real" service method. That way you have two ways of calling it, async and non-async.
Have the controller method store the Future returned by the service in the Session and then return. Then the when the client polls the controller (on a different URL/method) the controller can get the Future out of the session and call isDone() on it.
1 Comment
Michael Piefel
How do you properly deal with
Future not being serializable?