2

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.

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

Alen Peter
  • 126
  • 4
  • 10

1 Answers1

1

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.

hugh
  • 2,237
  • 1
  • 12
  • 25
  • Very interesting, thanks for giving the hint. Is it possible using REST API ? – Alen Peter Jul 04 '15 at 19:03
  • I believe the most common pattern is polling - the client makes a request to start a session, then periodically sends another request to check on its status. Once all results are complete and have been collected by the client, the server removes the session. This doesn't scale fantastically, since the client is making many requests, and if the client quits the server will not be aware and will continue performing their task. – hugh Jul 04 '15 at 19:17
  • yes, you are right. but what i am thinking is there should be some technique to solve this kind of use case. – Alen Peter Jul 05 '15 at 04:33