@Async
작업을 실행하는 내 컨트롤러 안에 몇 가지 방법이 있습니다.Spring MVC에서 @Async 메소드 결과를 반환하고 Ajax 클라이언트로 리턴한다.
@Async
public Future<String> getResultFromServer(){
String result = ......
return new AsyncResult<String>(result);
}
메서드 실행 시간은 최대 1 분입니다. 필요한 것은 AJAX/JQuery를 사용하여 클라이언트 측에 결과를 반환하는 것입니다.
@Async
메소드 실행 여부와 상관없이 클라이언트가 매초마다 서버를 요청하는 것을 원하지 않습니다. 난 그냥 내 연결을 계속 누른 다음 결과를 서버에 "푸시"하고 싶습니다.
@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();
}
}
이 점은 Comit 모델과 매우 비슷하지만 일반적으로 혜성에 익숙하지 않다는 것을 알고 있습니다.
내 질문에 어떻게 JavaScript/JQuery를 사용하여 클라이언트 쪽에서 연결을 열어 둘 수 있습니까?
내 @RequestMapping(value="/async.do", method=RequestMethod.POST)
메서드는 결과를 클라이언트에 전달합니까?
어떻게이/파트 2를 결국 해결 했습니까? – happybuddha