Asynchronous processing
The workflow for a servlet is: First,after theservlet receives the request, it needs to preprocess the data that was requested for modification. It then calls some of the methods of the business interface to complete the business process. Finally, the response is submitted based on the processing result. At this point, theServlet thread ends. In this process, if any one of the tasks does not end, theServlet thread is in a blocking state knowing that the business method has finished executing. For larger applications, it is easy to reduce the performance of the program.
Servlet3.0 has done a groundbreaking work on this issue, and now by using Servlet3.0 's asynchronous processing mechanism, the previous Servlet can be The processing process is adjusted to the following procedure.
First, after theServlet accepts the request, it may need to preprocess the data that the request carries
Theservlet thread then forwards the request to an asynchronous thread to perform business processing, and the thread itself returns to the container, at which time the servlet has not generated the response data, and after the asynchronous thread has finished processing the business, The response data can be generated directly, or the request will continue to be forwarded to the other Servlet. This way, theServlet thread is no longer stuck in a blocking state to wait for the processing of the business logic, but instead returns directly after initiating the asynchronous.
The asynchronous processing mechanism can be applied to both Servlet and filter components, because the asynchronous processing mode differs fundamentally from the normal working mode, and the asynchronous processing feature is not turned on by default, and if you want to use this attribute, you must enable it as follows:
The asyncsupported property is provided by the @WebServlet and @WebFilter annotations , and the default value for this property is false , to enable asynchronous processing support, simply set the value of the property to true . Take @WebFilter As an example and configure it as follows:
Example:
@WebFilter and @WebFilter annotations for asynchronous processing
@WebFilter (urlpatterns= "/chfilter", asyncsupported = True)
public class Demofilter implements filter{
}
If you choose to Configure a Servlet or filter in Web. XML, you can < in Servlet3.0 Add <async-supported> sub tags to servlet> and <filter> tags , The default value for this label is false, and to enable asynchronous processing support, set it to true .
Example:
configuring asynchronous Processing in Web. XML
<servlet>
<servlet-name>CharServlet</servlet-name>
<servlet-class>footmark.servlet.CharServlet</servlet-class>
<async-supported>true</async-supported>
</servlet>
JSP detail--Asynchronous processing