I will try to summarize what I learned. To understand the problem solved by Servlet 3.0 and Servlet 3.1, let's look at it as follows:
Before servlet 3.0:
Long streams caused starvation. Prior to Servlet 3.0, specific container solutions were developed for these long flows, in which we can create a separate workflow for a difficult task and then return a response to the client. The servlet thread returns to the servlet pool after the workflow starts. Tomcats Comet, WebLogics FutureResponseServlet and WebSpheres Asynchronous request The dispatcher is one example of the implementation of asynchronous processing.
(For more details see link 1. )
Servlet 3.0 Async:
Actual work can be delegated to the implementation of the thread pool (regardless of the specific solution container). The Runnable implementation will do the actual processing and will use AsyncContext to send a request to another resource or record a response. We can also add an AsyncListener implementation to an AsyncContext object to implement callback methods.
(For more details see link 1. )
Servlet 3.1 NIO:
Servlet 3.0 allowed asynchronous request processing, but only traditional I / O was allowed. How does the processing of traditional I / O affect? Well, if the data arriving at the server (i / o) is blocked or broadcast slower than the server can read, then the server thread must wait for this data. On the other hand, if data is being written to ServletOutputStream slowly, the client stream must wait. This problem is solved using the ReadListener and WriteListener . They are registered in ServletInputStream and ServletOutputStream . Listeners have callback methods that call when content is readable or can be written without blocking.
(For more details see link 2. )
Credits http://www.journaldev.com/2008/async-servlet-feature-of-servlet-3
https://blogs.oracle.com/arungupta/entry/non_blocking_i_o_using
code4kix Oct 25 '16 at 4:16 2016-10-25 04:16
source share