Servlet 3.0 supported by asynchronous traffic

I am trying to understand under what circumstances a tag is async-supported

needed in web.xml to handle an async servlet with Jersey. If I am doing any asynchronous work, I usually put it there. But to illustrate, I have set up a simple device

@GET
@Produces(MediaType.APPLICATION_JSON)
public void myService(@Suspended AsyncResponse response) {
    new Thread(new Runnable() {
        @Override
        public void run() {               
            response.resume(someResponseObject);
        }
    }).start();
}

      

In this case, if I don't put async-supported

in my web.xml, it works fine.

Does this not work asynchronously as it seems to me, or are there some specific operations I need to do before enabling it async-supported

?

+3


source to share


1 answer


A parameter async-supported

in the web.xml file or equivalent servlet annotation is @WebServlet(... asyncSupported=true)

used to specify at the servlet level the potential long running background work to be processed in a separate thread from the one that handles the request. The thread handling the request is not blocked for this background work, the doGet () or doPost () method is returned, and the thread can be used to process another request. The task will be queued and processed by a thread from a thread initiated when the application starts.



It actually has nothing to do with the Jersey Asyncres which is handled by the Jersey implementation. Jersey REST Service is not a servlet.

0


source







All Articles