I have a web service running which will be used by a client side mobile application. One of the services is to return an array of JSON objects (over 1000 objects), each object of considerable size. The whole computation on the server side takes some time, and that is not a good user experience. So i was hoping to send the data in chunks, say 10 objects per chunk, such that this data occupies the screen and when he scrolls, or when the data is ready, the screen is filled with the newly acquired data from the latest chunk received.

I use a Jersey framework and send a Java Response object as the return object. Is it possible to achieve the chunked-transfer in this scenario?. The code is something like this.

@Path("/doSomething")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response doSomething() {

    List<Object> myObj = getMyObj();
    /* getMyObj returns a list of Objects, each object of considerable size
    * the whole computation of getMyObj takes some time
    */
    return Response.ok(myObj).build();
}
有帮助吗?

解决方案

Your scenario sounds like server push.

You could try to use Atmosphere framework with your Jersey service to achieve your goal.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top