JSP detail--Asynchronous processing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.