Somebody just pointed out that AsyncContext.start() is a way to start a thread from within a Web Container. I am wondering what is the intended use-case for which this call was added to Java EE?
Somebody just pointed out that AsyncContext.start() is a way to start a thread from
Share
AsyncContext.start() is unlikely to start a new thread. It will almost certainly use a container thread (from the same thread pool used to process requests). Tomcat, for example, will always use a container thread from the request processing thread pool.
The use case is anything where you don’t want the ‘main’ thread to have to wait for whatever you put in the Runnable to complete before the main thread can continue.
Most of the examples I can think of are rather contrived but if you had some sort of messaging application implemented using Servlet 3.0 async with 5 connected clients the main thread might iterate through the AsyncContext’s of each of the 5 clients and call start() on each context to send a broadcast message. That way the main thread is not held up by a slow client.