About Question enthuware.jwpv6.2.594 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

About Question enthuware.jwpv6.2.594 :

Post by himaiMinh »

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

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.594 :

Post by admin »

The JavaDoc API description for addListener method says:
"Registers the given AsyncListener with the most recent asynchronous cycle that was started by a call to one of the ServletRequest#startAsync methods.
The given AsyncListener will receive an AsyncEvent when the asynchronous cycle completes successfully, times out, or results in an error."
It doesn't talk about what happens if ac.start() is called again.

I have updated the explanation to make it clear.

thank you for your feedback!
Paul.

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.594 :

Post by himaiMinh »

Hi, admin, thanks for your reply and update.
But in this code:

Code: Select all

AsyncContext ac=request.startAsync(); // line 1
//onStartAsync is not called here by the container
ac.addListener(myAsyncListener);  //line 2
//onStartAsync is not called here as the async process has already started.
onStartAsync method should be called after line 2 (after the AsyncContext object has been created in line 1).
But in this moment, the async process has already started and calling onStartAsync is never invoked by the container.

The container does not call the onStartAsync after line 1 and before line 2.

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.594 :

Post by admin »

Yes, you are right. I am just saying that the API description doesn't make it clear.
-Paul.

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests