Read a huge result set from HttpServiceClient and display them in chunks


Read a huge result set from HttpServiceClient and display them in chunks



Im writting a Java APP wich reads a huge chunk of data :


try {
//Build the URL

getMethod = new GetMethod(url);

SimpleHttpResponseParser parser = new SimpleHttpResponseParser();

httpServiceClient.getRequest(...); //This takes about 10 minutes


List<ApiMessage> messages = objectMapper.readValue(parser.getHttpResponse()); //Convert the JSON Response into actual Java Object

for (ApiMessage m : messages) {
convertedMessages.add(ApiMessageMapper.map(m)); //Add each message to a more suidable data set to be painted later
}
//Return the data and such ...
}



This request takes way to long to handle it. I dont want the user to wait over 10 minutes to see the results.



Is there a way to paint by result sets of 50 or so and keep downloading the remaining data in the background?





You should start a thread for doing it. And keep main thread unblocked.
– Gaurav Srivastav
Jun 29 at 17:40




1 Answer
1



Try to implement pagination. Usually, servers allow returning a limited number of results by specifying offset and limit.


offset


limit



On the first call set


offset=0
limit=50



On the next call


offset=51
limit=50



and so on...



Another way is to use server push using WebSockets, but it will be a more complex implementation.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV