java异步回调函数返回的状态如何通知给前台?

如题,有了异步函数也处理了数据,但是怎么反馈给前台呢?给点思路也好

萧十郎
浏览 856回答 4
4回答

慕斯王

WebSockets can make a web page dynamic and interactive. However in many cases a combination of Ajax and HTTP streaming and/or long polling could provide a simple and effective solution. For example news, mail, and social feeds need to update dynamically but it may be perfectly okay to do so every few minutes. Collaboration, games, and financial apps on the other hand need to be much closer to real time. Latency alone is not a deciding factor. If the volume of messages is relatively low (e.g. monitoring network failures) HTTP streaming or polling may provide an effective solution. It is the combination of low latency, high frequency and high volume that make the best case for the use WebSocket. 看了springboot websocket文档说的,什么时候用轮询,什么时候用websocket说得很清楚,我还是乖乖的用轮询吧

墨色风雨

个人觉得最简单的是用短轮询方式: 前台发送请求A,调用后台方法,后台方法启动任务后返回结果。拿到结果后,前台定期(1s)通过请求B查询后台任务是否处理完成。

鸿蒙传说

只能再给一个接口去轮询了,服务器又不能直接给客户端发 http 请求。

青春有我

轮询也可以,要不前台和后台建立WebSocket连接,数据处理好之后,服务端向客户端直接推送反馈信息。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java