Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

servlet loading

Posted on 2014-03-26
1
524 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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…

840 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