有没有进行发射后不管AJAX请求的方法吗? [英] Is there a way to perform fire-and-forget AJAX request?

查看:133
本文介绍了有没有进行发射后不管AJAX请求的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个Web应用程序。当程序切换信道,它发送一个关闭AJAX请求与老渠道服务器。作为服务器响应,应用程序只发送一个开放的请求到服务器以打开一个新的信道。大多数时候,这种近距离等待做开-WAIT-做全面的运行速度不够快,但在特殊渠道的情况下,关闭的时间超过5秒,这是不可接受的。

I'm working on a web app. When the program switches channel, it sends a "close" AJAX request to the server with the old channel. As the server responses, the app just sends an "open" request to the server to open a new channel. Most of times, this close-wait-done-open-wait-done round runs fast enough, but in case of a special channel, close takes longer than 5 secs, which is unacceptable.

我已经为这些频道的关闭请求短超时,并返回,但新的开放的要求挂起,直到服务器响应旧的关的要求,所以超时只是把问题了。

I've set a short timeout for these channels' "close" requests, and it returns, but the new "open" request hangs until the server responses the old "close" request, so timeout just pushed the problem away.

我已经设置了的setTimeout()为长近,所以我的程序调用关闭,这将被推迟,而新的开放之前执行它,但它也只是折腾这个问题,时的setTimeout()安打,会有一个很长的请求在后台,它吃了浏览器的AJAX请求池,并与一些运气,使伪Ajax的挂在随机AJAX请求。

I've set up a setTimeout() for the long close, so as my program calls the "close", it will be delayed, and the new "open" performs before it, but it's also just tossing the problem, when setTimeout() hits in, there will be a long request "in the background", which eats up the browser's ajax request pool, and with some luck, causes pseudo-ajax-hanging at a random AJAX request.

该应用程序已在关闭请求的结果不感兴趣,因此它可以被删除,即使它失败。

The app has no interest in the result of the "close" request, so it can be dropped, even if it fails.

什么是最好的做法来执行这样的发射后不管AJAX请求?

What's the best practice to perform such fire-and-forget AJAX requests?

(我在Linux上使用Chromium浏览器,但应用程序应该在Firefox上运行了。)

(I'm using Chromium browser on Linux, but the app should run on Firefox, too.)

推荐答案

您可以使用servlet的3.0异步功能。您可以立即提交响应为你的亲密请求,并启动新的线程做进一步的服务器处理。
您可以参考以下链接在同一的更多信息。
<一href=\"http://www.javaworld.com/article/2077995/java-concurrency/asynchronous-processing-support-in-servlet-3-0.html\" rel=\"nofollow\">http://www.javaworld.com/article/2077995/java-concurrency/asynchronous-processing-support-in-servlet-3-0.html

You can use servlet 3.0 Async feature. You can commit the response immediately for your close request and start new thread to do further server processing. You can refer below link for more information on the same. http://www.javaworld.com/article/2077995/java-concurrency/asynchronous-processing-support-in-servlet-3-0.html

这篇关于有没有进行发射后不管AJAX请求的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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