猿问

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

如题,有了异步函数也处理了数据,但是怎么反馈给前台呢?给点思路也好
慕仙森
浏览 1808回答 2
2回答

白板的微信

WebSocketscanmakeawebpagedynamicandinteractive.HoweverinmanycasesacombinationofAjaxandHTTPstreamingand/orlongpollingcouldprovideasimpleandeffectivesolution.Forexamplenews,mail,andsocialfeedsneedtoupdatedynamicallybutitmaybeperfectlyokaytodosoeveryfewminutes.Collaboration,games,andfinancialappsontheotherhandneedtobemuchclosertorealtime.Latencyaloneisnotadecidingfactor.Ifthevolumeofmessagesisrelativelylow(e.g.monitoringnetworkfailures)HTTPstreamingorpollingmayprovideaneffectivesolution.Itisthecombinationoflowlatency,highfrequencyandhighvolumethatmakethebestcasefortheuseWebSocket.看了springbootwebsocket文档说的,什么时候用轮询,什么时候用websocket说得很清楚,我还是乖乖的用轮询吧

心有法竹

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

相关分类

JavaScript
我要回答