Servlet (2) lifecycle

Source: Internet
Author: User

Servlet lifecycle Phases

1, create the object

Creating objects is created only the first time a user accesses a Web server, the second time, or more often, the Servlet object already exists and is no longer created.


Object creation Principle:



The first time a user accesses a Web server, the server passes the URL address entered by the user, Parse the Web.xml file, get the full class name of the Servlet object, and then create the Servlet object through the reflection mechanism, and when the server is accessed again, the Servlet object is no longer created because it already exists.


2, Initialize

At this point, the Servlet object has been created. Invokes the Init () method of the Servlet object for initialization. Initialization is done after the object is created, and is performed only once.

3, processing requests

Is the core, call the servlet's service () method to process the request. Executable multiple times.


4, Object destruction

When the Servlet object is not accessed for a long time, or the container is closed, the Destroy () method is invoked before the destruction to prepare for destruction.


Summary: The servlet is single-instance, initialized once, and has thread-safety issues.

The lifecycle of the servlet is managed by the Web container, and the programmer cannot change the control, but also to emphasize that our job is to accomplish the concrete implementation of the methods in the servlet.


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.