서블릿 (this example)과 통신하기 위해 requestbuilder를 사용하는 예제 프로젝트 StockWatcher가 있습니다. 서블릿을 비동기로 만들고 싶습니다. 나는의 doGet 메서드에 다음 줄을 추가 한 :비동기 서블릿 3.0이 포함 된 GWT requestbuilder
final AsyncContext ac = request.startAsync();
ac.setTimeout(1 * 60 * 1000);
ac.addListener(new AsyncListener() {
@Override
public void onError(AsyncEvent arg0) throws IOException {
System.out.println("onError");
}
public void onComplete(AsyncEvent event) throws IOException {
System.out.println("onComplete");
queue.remove(ac);
}
public void onTimeout(AsyncEvent event) throws IOException {
System.out.println("onTimeout");
queue.remove(ac);
}
@Override
public void onStartAsync(AsyncEvent arg0) throws IOException {
System.out.println("onStartAsync");
}
});
queue.add(ac);
비동기 주석 추가 : @WebServlet(asyncSupported=true)
과와의 doGet 방법의 나머지 부분을 변경 :
PrintWriter out = ac.getResponse().getWriter();
out.println("Something");
out.flush();
이제 돌아 아무것도 없다. 내가 틀린 게 뭐야? 클라이언트 측에서 뭔가를 변경해야합니까? 글래스 피쉬 3에는 오류가 표시되지 않습니다.
왜 대기 중입니까? add (ac); 두번? –
맞아, 내 실수 야. 하지만 그건 내 문제를 해결하지 못한다. – Mike