Return @Async method result in Spring MVC and return it to Ajax client - continuation

别等时光非礼了梦想. 提交于 2020-01-03 17:28:39

问题


This is continuation of this question:

Return @Async method result in Spring MVC and return it to Ajax client

I have @Async task which calculates something and return it to the Future the calculation happens on the request and might take up to 15 minutes. I don't want to create new Ajax request every few seconds to check whether calculation is done and I don't want to keep my connection Open for up to 15 minutes till result is calculated.

What might be the best solution for Spring MVC in such cases?


回答1:


I agree, you definitely don't want to keep the connection open.

With respect to eliminating polling requests, I'm not sure you have a choice.

Remember HTTP is a stateless request/response protocol.

You will need some sort of polling to check on the status.

Can you send out an email to the user containing a link to the calculation once it is done?

You can also take a look at the Comet framework. Comet allows us to extend HTTP capabilities by keeping open a connection and allowing the server to push data to the client.



来源:https://stackoverflow.com/questions/7914966/return-async-method-result-in-spring-mvc-and-return-it-to-ajax-client-continu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!