返回@Async方法导致Spring MVC和返回给Ajax客户 - 延续 [英] Return @Async method result in Spring MVC and return it to Ajax client - continuation

查看:280
本文介绍了返回@Async方法导致Spring MVC和返回给Ajax客户 - 延续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是延续了这样的问题:

This is continuation of this question:

<一个href="http://stackoverflow.com/questions/7907011/return-async-method-result-in-spring-mvc-and-return-it-to-ajax-client">Return @Async方法导致Spring MVC和它返回到Ajax客户

我有 @Async 的任务,它计算的东西,其返回到未来的计算发生在该请求,并可能需要长达15分钟。我不希望创建新的Ajax请求每隔几秒钟检查是否计算完成,我不想让我的连接打开长达15分钟,直到结果的计算方法。

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.

这可能是Spring MVC的在这种情况下,最好的解决办法?

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

推荐答案

我同意,你绝对不希望保持连接。

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.

记住HTTP是一个无状态的请求/响应协议。

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?

您也可以看一看彗星框架。彗星让我们通过保持开放的连接,并允许服务器将数据推送到客户端扩展HTTP的功能。

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.

这篇关于返回@Async方法导致Spring MVC和返回给Ajax客户 - 延续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆