어느 가을날의 전환점

TOMCAT|톰켓 web.xml의 Servlet 로드 옵션 <load-on-startup> 본문

Development

TOMCAT|톰켓 web.xml의 Servlet 로드 옵션 <load-on-startup>

어느가을빛 2012. 3. 28. 09:12

web.xml

<servlet>
  <servlet-name>>HellowServlet</servlet-name>
  <servlet-class>est.HellowServlet</servlet-class>
  <init-param>
    <param-name>............
    <param-value>............
  </init-param>
  <!-- Load this servlet at server startup time -->
  <load-on-startup>0</load-on-startup>
</servlet>


컨텍스트의 웹 애플리케이션이 톰캣 서버에 의해 인식되는 시점에 로드 됨(init() called)

(Tomcat Server가 시작하는 시점은 아님)


load-on-startup 엘리먼트에 적어준 숫자가

  1) 음의 정수인 경우: 그 서블릿에 접근될 때 (즉, load-on-startup 엘리먼트가 없는 경우와 동일함)

  2) 0 이거나 양의 정수인 경우: 그 서블릿이 배치(deploy)될 때 (즉, 컨텍스트가 인식될 때) 

숫자가 작은 것 부터 먼저 로딩된다.


The life cycle of a servlet is controlled by the container in which the servlet has been deployed. When a request is mapped to a servlet, the container performs the following steps.

  1. If an instance of the servlet does not exist, the Web container

    1.1. Loads the servlet class.

    1.2. Creates an instance of the servlet class.

    1.3. Initializes the servlet instance by calling the init method. Initialization is covered in Initializing a Servlet.

  2. Invokes the service method, passing a request and response object. Service methods are discussed in the section Writing Service Methods.

A 0 value on load-on-startup means that point 1 is executed when a request come to that servlet. Other values means that point 1 is executed at container startup.

The load-on-startup element indicates that this servlet should be loaded (instantiated and have its init() called) on the startup of the web application. The optional contents of these element must be an integer indicating the order in which the servlet should be loaded. If the value is a negative integer, or the element is not present, the container is free to load the servlet whenever it chooses. If the value is a positive 128 integer or 0, the container must load and initialize the servlet as the application is deployed. The container must guarantee that servlets marked with lower integers are loaded before servlets marked with higher integers. The container may choose the order of loading of servlets with the same load-on-start-up value.


#참조
1) 
http://stackoverflow.com/questions/809775/what-does-the-servlet-load-on-startup-value-of-0-zero-signify



0 Comments
댓글쓰기 폼