About Question enthuware.jwpv6.2.594 :
Posted: Sat Apr 30, 2016 7:37 pm
Hi, I tried to demo the scenario where another asynch process starts , but the onStartAsync method is not called.
Code: Select all
@WebListener
public class MyListener implements AsyncListener {
...
public void onStartAsync(AsyncEvent event){
System.out.println("Async Listener on start");
}
...
}
Code: Select all
@WebServlet(urlPatterns="/foo/*",
name = "NullServlet",
asyncSupported = true)
public class NullServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp){
MyListener myAsyncListener = new MyListener();
req.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true);
final AsyncContext ac = req.startAsync();
ac.addListener(myAsyncListener);
ac.start(new Runnable(){
public void run(){
System.out.println(" I am async thread.");
}
});
//try to start a new async process,
//but the listener's onStartAsync method is not called.
ac.start(new Runnable(){
public void run(){
System.out.println(" I am async thread 1 .");
}
});
}
}
I am async thread.
I am async thread 1 .
Async Listener on timeout
Async Listner on complete