pushNpop
pushNpop

Reputation: 2064

Spring MVC and @Async

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.

Upvotes: 3

Views: 3580

Answers (1)

sourcedelica
sourcedelica

Reputation: 24040

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.

Upvotes: 11

Related Questions