3

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.

1 Answer 1

11

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.

Sign up to request clarification or add additional context in comments.

1 Comment

How do you properly deal with Future not being serializable?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.