如何在Java Web API中获得单个请求的多个响应

编程入门 行业动态 更新时间:2024-10-17 00:19:47
本文介绍了如何在Java Web API中获得单个请求的多个响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设我有一个客户端,该客户端将请求发送到服务器以生成1到100之间的数字,并将响应发送回客户端。假设从1到100生成数字是非常繁琐的工作,并且需要大量资源,所以我的服务器将开始生成数字,并在服务器上生成数字后立即将数字发送给客户端,而不是生成所有数字并发送

suppose i have a client which sends the request to server to generate numbers from 1 to 100 and send the response back to client. Assume that generating numbers from 1 to 100 is very tedious job and it requires lot of resources so my server will start generating the numbers and sends the numbers to client as soon as the number is generated on server, instead of generating all number and sending the response at once to client.

就像翻页一样。如果您打开一个页面,我们可以看到,该页面将继续在底部更新新产品,而不是一次列出所有产品。

It is something like flipkart page. if you open a page we can see that, the page is keep on updating with new products at the bottom, instead of listing all products once at one shot.

可以一个人可以为我的简单用例建议我一些有效的Java技术吗?

Can any one please suggest me some efficient technique in java for my simple use case ?

推荐答案

这听起来像Java 7的 Websocket API 。使用传统的HTTP是不可能的,因为交互遵循请求-响应模式(尽管诸如轮询和长轮询之类的模式也可以达到相同的效果)。 WebSocket允许来自服务器的真实推送通知,因此客户端可以在数据可用时立即接收数据。

This sounds like a job for Java 7's Websocket API. Using traditional HTTP it would not be possible because interactions followed a request-response pattern (although patterns such as polling and long-polling can achieve the same effect). WebSockets allow genuine push notifications from the server, so the client can receive the data as soon as it becomes available.

更多推荐

如何在Java Web API中获得单个请求的多个响应

本文发布于:2023-11-02 17:02:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552934.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   如何在   Web   Java   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!