在Spring MVC中返回@Async方法结果并将其返回到Ajax客户端 - 继续

时间:2022-04-16 21:07:09

This is continuation of this question:

这是这个问题的延续:

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

在Spring MVC中返回@Async方法结果并将其返回给Ajax客户端

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.

我有@Async任务,它计算一些东西并将其返回到Future,计算在请求中发生,可能需要15分钟。我不想每隔几秒创建一个新的Ajax请求来检查计算是否完成,我不想保持连接打开最多15分钟,直到计算结果。

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

在这种情况下,Spring MVC可能是最好的解决方案吗?

1 个解决方案

#1


0  

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.

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

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.

您还可以查看Comet框架。 Comet允许我们通过保持打开连接并允许服务器将数据推送到客户端来扩展HTTP功能。

#1


0  

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.

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

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.

您还可以查看Comet框架。 Comet允许我们通过保持打开连接并允许服务器将数据推送到客户端来扩展HTTP功能。