I think, I don't really get concept of asynchronous Servlet. First of all, why we had to mark asyncSupport = true? Whether it true/false I can created ThreadPool and add task to it, to execute that task asynchronous, right? So what is the difference, what I cannot achieve without asyncSupport? Any example appreciated.

有帮助吗?

解决方案

AsyncContext is convenient when you do need to keep the connection until you have some data to return after some time in the future without blocking the thread.

In one project I had a remote client which connected to the server and waited (long timeout) for the command from server. So called long-polling approach. Once server has some data to send it takes the AsyncContext and commits the response. It's very convenient as otherwise we would need to block a thread.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top