如何在Java Web API中获得单个请求的多个响应 [英] How to get multiple response for single request in java web api

查看:180
本文介绍了如何在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中获得单个请求的多个响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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