I Have some method inside my Controller which executes @Async task
@Async
public Future<String> getResultFromServer(){
String result = ......
return new AsyncResult<String>(result);
}
The method execution time is up to 1o minutes. All I need to do is just to return result to client side which will be connected using AJAX/JQuery.
I don't want the client to request my server every second whether @Async method executed or not. I just want to keep my connection open and then just "push" result to Server.
@RequestMapping(value="/async.do", method=RequestMethod.POST)
public void getResult(HttpServletResponse res){
String result = null;
PrintWriter out = res.getWriter();
Future<String> future = getResultFromServer();
try {
if (future.isDone())
result = future.get();
out.println(result);
out.close();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
I understand that this very close to Comit model, but I'm not familiar with comet in general.
My question is how can I keep connection open on client side using JavaScript/JQuery?
and will my @RequestMapping(value="/async.do", method=RequestMethod.POST) method push result to the client?