Solved

servlet loading

Posted on 2014-03-26
1
508 Views
Last Modified: 2014-04-24
Hi,

I was reading as below(http://www.javatpoint.com/load-on-startup)

    <servlet>  
       <servlet-name>servlet1</servlet-name>  
       <servlet-class>com.javatpoint.FirstServlet</servlet-class>  
       <load-on-startup>0</load-on-startup>  
      </servlet>  
     
      <servlet>  
       <servlet-name>servlet2</servlet-name>  
       <servlet-class>com.javatpoint.SecondServlet</servlet-class>  
       <load-on-startup>1</load-on-startup>  
      </servlet>  
     
     ...  
    </web-app>  

There are defined 2 servlets, both servlets will be loaded at the time of project deployment or server start. But, servlet1 will be loaded first then servlet2.
Passing negative value

If you pass the negative value, servlet will be loaded at request time, at first request.


I have not clearly understood why servlet1 loaded then servlet2. What it means by loading one servlet after other servlet.

also what it mean by servlet loaded at request time for negative value.

please advise
Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
1 Comment
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 39957812
I have not clearly understood why servlet1 loaded then servlet2.
Because servlet1 has a LOWER <load-on-startup> value (0) defined in the web.xml than load-on-startup value for servlet2 (1), that is why servlet1 will be loaded first, and then servlet2.

What it means by loading one servlet after other servlet.
Or in general you may ask, "What does it mean to load a servlet?"...

Well, the servlet container does a number of things in order to "load" a servlet. First it creates an instance of the servlet class, so something like....     Servlet servlet1 = new com.javatpoint.FirstServlet();     then once it has an instance (object) of your servlet class it call the init method on it, like....     servlet1.init(config);       where 'config' is some information that the container passes to your servlet. Once that is done, your servlet is "loaded"

So to go back to your original question, the order of "loading" just controls the order in which the above process happens to each configured servlet. This may be useful to control because, for example, servlet2 may depend on things done in the loading of servlet1, and so the web.xml is configured to make sure the servlet1 loads first.

what it mean by servlet loaded at request time
So, lastly, this may now be obvious, but the negative value for <load-on-startup> just means that instead of the servlet container doing all the above when the servlet container starts up, it may "defer" this process to a later time. For example, the servlet container might not "load" the servlet straight away, but at a later point in time the servlet container receives a request that needs to be fulfilled by that servlet, so it "loads" the servlet (ie. does all the above steps) at that point and then immediately passes the request to the newly loaded servlet.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now