views:

167

answers:

0

I have example project StockWatcher using requestbuilder to communicate with servlet (this example). I want to make servlet asynchronous. I have added the following lines to the doGet method:

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); 

added asynchronous annotation: @WebServlet(asyncSupported=true) and changed the rest of doGet method with:

PrintWriter out = ac.getResponse().getWriter();
out.println("Something");
out.flush();

Now there is nothing returning. What do I wrong? Have to change something in client side? Glassfish 3 does not show any errors.