System.out.println(req.getAttribute(AsyncContext.ASYNC_QUERY_STRING));
System.out.println(req.getAttribute(AsyncContext.ASYNC_SERVLET_PATH));
if(req.getAttribute("ok1") == null) {
System.out.println("===before start async:" + req.isAsyncStarted());
final AsyncContext asyncContext = req.startAsync();
System.out.println("===after start async:" + req.isAsyncStarted());
asyncContext.setTimeout(10L * 1000);
asyncContext.addListener(new AsyncListener() {
@Override
public void onComplete(final AsyncEvent event) throws IOException {
System.out.println("=====async complete");
}
@Override
public void onTimeout(final AsyncEvent event) throws IOException {
}
@Override
public void onError(final AsyncEvent event) throws IOException {
}
@Override
public void onStartAsync(final AsyncEvent event) throws IOException {
}
});
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(3L * 1000);
} catch (InterruptedException e) {
}
req.setAttribute("ok1", "true");
req.setAttribute("msg", "success");
asyncContext.dispatch();
System.out.println("===after dispatch before handle:" + req.isAsyncStarted());
}
}).start();
return;