Solved

servlet loading

Posted on 2014-03-26
1
554 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
[X]
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
1 Comment
 
LVL 36

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
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 will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

726 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