问题
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