To handle long the running process we are using SpringMVC DeferredResult
to send the data to the browser, but after certain period of time the browser returns no data received, while the process is still running in the back end. it works fine in localmachine but when it is deployed in amazon EC2 instance we face the problem.
how to solve this issue and how to send data periodically to Browser.
Here is my code where the process is delayed by 90 sec
@RequestMapping("/myDefferedResult1")
@ResponseBody
public DeferredResult<List<String>> myDefferedResult2(final HttpServletResponse httprep) {
final DeferredResult<List<String>> deferredResult = new DeferredResult<List<String>>(null, Collections.emptyList());
this.chatRequests.put(deferredResult, 0);
try {
Thread.sleep(90000L);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
deferredResult.onCompletion(new Runnable() {
@Override
public void run() {
System.out.println("completeion");
chatRequests.remove(deferredResult);
}
});
List<String> messages = new ArrayList<String>();
messages.add("hi");
messages.add("hello");
if (!messages.isEmpty()) {
deferredResult.setResult(messages);
System.out.println("setresult");
}
return deferredResult;
}
the browser returns No data received after sometime