如题,有了异步函数也处理了数据,但是怎么反馈给前台呢?给点思路也好
2 回答
白板的微信
TA贡献1883条经验 获得超3个赞
WebSocketscanmakeawebpagedynamicandinteractive.HoweverinmanycasesacombinationofAjaxandHTTPstreamingand/orlongpollingcouldprovideasimpleandeffectivesolution.Forexamplenews,mail,andsocialfeedsneedtoupdatedynamicallybutitmaybeperfectlyokaytodosoeveryfewminutes.Collaboration,games,andfinancialappsontheotherhandneedtobemuchclosertorealtime.Latencyaloneisnotadecidingfactor.Ifthevolumeofmessagesisrelativelylow(e.g.monitoringnetworkfailures)HTTPstreamingorpollingmayprovideaneffectivesolution.Itisthecombinationoflowlatency,highfrequencyandhighvolumethatmakethebestcasefortheuseWebSocket.看了springbootwebsocket文档说的,什么时候用轮询,什么时候用websocket说得很清楚,我还是乖乖的用轮询吧
心有法竹
TA贡献1866条经验 获得超5个赞
个人觉得最简单的是用短轮询方式:前台发送请求A,调用后台方法,后台方法启动任务后返回结果。拿到结果后,前台定期(1s)通过请求B查询后台任务是否处理完成。
添加回答
举报
0/150
提交
取消