Servlet - 03 - servlet life cycle

 


 

Servlet life cycle (1)

 Conclusion: Close the first called to the server.

Whether Tomcat server has opened up a number of threads, servlet will create an object, to call the service method, because different threads incoming parameter req, rep is not the same, so the result is not the same.

 

 

 

 

 

 

   

Servlet life cycle:

* 1. Conclusion: closed from the first called to the server.

When the time to start Tomcat, tomcat calls the initialize method of the servlet class --init (), then initialize an object, then call the service ().

Behind the Tomcat server regardless of the number of threads created, how many service calls (),

Will not call the init ().

Finally, when we shut down when the Tomcat server, destroyed servlet, destroy trigger  execution method

 

2. Verify:

* Init  method : servlet  when the call is initiated to create

* Service  method while processing the request:

* Destory  method : When the server is shut down when the destruction servlet, destroy trigger  execution method

 

 

 

 

 

 

Servlet life cycle (2)

: Servlet life cycle is open from server to server shut down

 

We can configure the <load-on-startup> < / load-on-startup> web.xml in to set the load Servlet opportunity for the server to start.

* So, the servlet's lifecycle becomes open from server to server shut down.

 

 1.web.xml configuration:

 

 

2. load the server, console input results found servlet has not been called, init () is also called.

 

 

Guess you like

Origin www.cnblogs.com/EricShen/p/11444642.html
Recommended