문제

나는 조금 여기에.우리의 응용 프로그램에서 우리는 몇 가지 서블릿 정의됩니다.여기에서 발췌 web.xml 중 하나에 대한 servlet:

<servlet>
    <servlet-name>AxisServlet</servlet-name>
    <display-name>Apache-Axis Servlet</display-name>
    <servlet-class>com.foo.framework.axis2.http.FrameworkServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
</servlet> 

따라 내가 이해하는 가치에 대해 <load-on-startup> 은 양의 정수에 대한 순서를 얻을 자동으로 로드되.나는 구글에서만 응답에 걸쳐 온 나만 내 혼란에 추가됩니다.

도움이 되었습니까?

해결책

수지 3.0 이 행동을 문서화합니다.

로드-스테이트는 (선택적) 정수 값을 지정할 수 있습니다. 값이 0 이상인 경우 서블릿을로드하는 순서가 표시되며, 더 높은 숫자가있는 서블릿은 더 낮은 숫자를 가진 서블릿 후에로드됩니다.

그만큼 JSP 3.1 사양 (JSR 340) 14-160 페이지에서 이것을 말합니다.

요소 load-on-startup 이 서블릿은 웹 응용 프로그램 시작시로드 (인스턴스화 및 init)가 있어야 함을 나타냅니다. 이 요소의 요소 내용은 서블릿을로드 해야하는 순서를 나타내는 정수 여야합니다. 값이 네거티브 정수이거나 요소가없는 경우 컨테이너는 선택할 때마다 서블릿을 자유롭게로드 할 수 있습니다. 값이 양의 정수 또는 0 인 경우 컨테이너는 응용 프로그램이 배포 될 때 서블릿을로드하고 초기화해야합니다. 컨테이너는 더 낮은 정수로 표시된 서블릿이 더 높은 정수가 표시된 서블릿 전에로드되도록 보장해야합니다. 컨테이너는 동일하게 서블릿의 적재 순서를 선택할 수 있습니다. load-on-startup 값.

JSR뿐만 아니라 웹 컨테이너에 대한 문서도 확인하고 싶을 것입니다. 차이가있을 수 있습니다

다른 팁

짧은 대답: value> = 0은 웹 앱이 배포 될 때 또는 서버가 시작될 때 서블릿이로드되었음을 의미합니다. 값 <0 : 컨테이너가 느껴질 때마다 서블릿이로드됩니다.

긴 대답 (사양에서) :

로드-스테이트 up 요소는 웹 애플리케이션 시작 시이 서블릿이로드 (인스턴스화 및 init)를 호출해야 함을 나타냅니다. 이 요소의 선택적 내용은 서블릿을로드 해야하는 순서를 나타내는 정수 여야합니다. 값이 네거티브 정수이거나 요소가없는 경우 컨테이너는 선택할 때마다 서블릿을 자유롭게로드 할 수 있습니다. 값이 양의 128 정수 또는 0 인 경우 컨테이너는 응용 프로그램이 배포 될 때 서블릿을로드하고 초기화해야합니다. 컨테이너는 더 낮은 정수로 표시된 서블릿이 더 높은 정수가 표시된 서블릿 전에로드되도록 보장해야합니다. 컨테이너는 동일한로드 업 값으로 서블릿의 로딩 순서를 선택할 수 있습니다.

요청이 액세스하려고 할 때까지 서블릿이 시작되지 않음을 나타냅니다.

로드-스테이트 up이 0보다 크거나 동일하면 컨테이너가 시작되면 시작 값에 대한 하중의 오름차순 순서로 서블릿을 시작합니다 (예 : 0, 1, 2, 5, 10 등). .

서블릿 라이프 사이클

서블릿의 수명주기는 서블릿이 배치 된 컨테이너에 의해 제어됩니다. 요청이 서블릿에 매핑되면 컨테이너는 다음 단계를 수행합니다.

  1. 서블릿의 인스턴스가 존재하지 않으면 웹 컨테이너 :

    ㅏ. 서블릿 클래스를로드합니다

    비. 서블릿 클래스의 인스턴스를 만듭니다

    씨. init 메소드를 호출하여 서블릿 인스턴스를 초기화합니다 (초기화는 서블릿 생성 및 초기화)

  2. 컨테이너는 서비스 방법을 호출하여 요청 및 응답 개체를 전달합니다. 서비스 방법이 논의됩니다 쓰기 서비스 방법.

0 값 on load-on-startup 요청이 해당 서블릿에 오면 지점 1이 실행된다는 것을 의미합니다. 다른 값은 컨테이너 스타트 업에서 지점 1이 실행된다는 것을 의미합니다.

에 명시된 바와 같이 다른 대답이 로드에서 시작 문서 제은 수락가능하에 없는 다른 servlet 이에 우선 순위 적재 및 로드 중 배포합니다.최고의 사용을 로드 statup 을 로드하블릿 더 오래 걸리는 시간을 초기화를 잘하기 전에 처음 요청을 올 다음과 같블릿을 만드는 연결이 수영장 또는 네트워크를 호출 또는 부피가 큰 자원,이것은 상당한 응답 시간을 줄이기 위해 처음 몇 요청을 합니다.

  1. 값이 두 개의 서블릿에 대해 값이 동일하다면 Web.xml 파일 내부에서 선언 된 순서로로드됩니다.
  2. 컨테이너가로드하는 느낌이 들면 서블릿보다 0 이상 또는 네거티브 정수가 적재됩니다.
  3. 웹 컨테이너별로로드, 초기화 및 통화 init () 서블릿 메소드를 보장합니다.
  4. 서블릿에 대한 요소가없는 경우 웹 컨테이너가로드하기로 결정할 때로드 될 것입니다.

예, 값이 동일한 값을 가질 수 있습니다 ....로드에 숫자를주는 이유는 서버가 모든 서블릿을로드하기 위해 서버의 시퀀스를 정의하는 것입니다. 시작 값이 0 인 서블릿은 먼저로드되고 그 후 값 1이있는 서블릿이로드됩니다.

두 개의 서블릿이로드-온 스타트 up에 대해 동일한 값을 갖는 경우 web.xml에서 상단에서 아래로 선언 된 방식과로드됩니다. Web.xml에서 먼저 오는 서블릿이 먼저로드되고 그 후에는로드됩니다.

--> (Absence of load-on-start-up) tag First of all when ever servlet is deployed in the server, It is the responsibility of the server to creates the servlet object. Eg: Suppose Servlet is deployed in the server ,(Servlet Object is not available in server) client sends the request to the servlet for the first time then server creates the servlet object with help of default constructor and immediately calls init() . From that when ever client sends the request only service method will get executed as object is already available

If load-on-start-up tag is used in deployment descriptor: At the time of deployment itself the server creates the servlet object for the servlets based on the positive value provided in between the tags. The Creation of objects for the servlet classes will follow from 0-128 0 number servlet will be created first and followed by other numbers.

If we provide same value for two servlets in web.xml then creation of objects will be done based on the position of classes in web.xml also varies from server to server.

If we provide negative value in between the load on start up tag then server wont create the servlet object.

Other Scenarios where server creates the object for servlet.

If we dont use load on start up tag in web.xml, then project is deployed when ever client sends the request for the first time server creates the object and server is responsible for calling its life cycle methods. Then if a .class is been modified in the server(tomcat). again client sends the request for modified servlet but in case of tomcat new object will not created and server make use of existing object unless restart of server takes place. But in class of web-logic when ever .class file is modified in the server with out restarting the server if it receives a request then server calls the destroy method on existing servlet and creates a new servlet object and calls init() for its initilization.

If the value is <0, the serlet is instantiated when the request comes, else >=0 the container will load in the increasing order of the values. if 2 or more servlets have the same value, then the order of the servlets declared in the web.xml.

The servlet container loads the servlet during startup or when the first request is made. The loading of the servlet depends on the attribute "load-on-startup" in "web.xml" file. If the attribute has a positive integer(0 to 128) then the servlet is load with the loading of the container otherwise it loads when the first request comes for service.

When the servlet is loaded once it gets request then it is called "Lazy loading".

It is simple as you don't even expect.

If the value is positive it loaded when the container starts

If the value is not positive than the servelet is loaded when the request is made.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top