【发布时间】:2012-03-28 20:03:23
【问题描述】:
我有示例项目 StockWatcher 使用 requestbuilder 与 servlet (this example) 通信。我想让servlet异步。我在 doGet 方法中添加了以下几行:
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();
现在没有任何返回。我错了什么?必须在客户端更改某些内容吗? Glassfish 3 没有显示任何错误。
【问题讨论】:
-
你为什么要做 queue.add(ac);两次?
-
对,我的错。但这并不能解决我的问题
标签: gwt servlets asynchronous