开发者

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜