• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loads on startup problem in web.xml.

 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a confusion about loads on startup in web.xml, as per my knowledge, if we give the value 1 then , that servlet will execute first, and if the value is 2 then servlet will execute, after the first servlet, as here,

this is my web.xml:




this is my first.java




this is my second.java







so here second servlet's value is 2 in loads on startup in web.xml, if I try to execute second servlet, then it printed, mates, so I can not understand , it should print hello mates because first servlet's value is 1, so first servlet should print first, and also, I can not feel the less timing, means loads on startup consumes less time, please clearify this.
 
Tim Moores
Bartender
Posts: 2946
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlet load order has no bearing on servlet execution. In particular, invoking one servlet will not cause another to be invoked as well. How did you get that idea?

As to seeing a difference in performance, I would not expect any given the simplicity of both classes. You might see a difference if a servlet has lengthy initialization code to run, but not here.
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok fine, but I used "load on startup" two times in each (both) servlet individually, so I can not see the effect that which servlet should execute first, it executes normally, (when I execute first, it run and when I execute second , it run), so why google says me, that if we give positive value, it starts executing in accending order, I can not see a single difference even...
 
Tim Moores
Bartender
Posts: 2946
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again: load order had nothing to do with execution. The servlet code is executed when it is invoked, regardless of when its class was loaded.

Maybe you can post the link to what you read, and we can either point out where that is incorrect, or where you may have misunderstood it.
 
Dave Tolls
Ranch Hand
Posts: 1895
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Add the above method into each servlet, putting a suitable message in so you can identify them.

This is the method that gets called when the servlet is initialised.
The load-on-startup simply tells the engine to load the marked servlet(s) when the server starts up. Ones that are not marked load-on-startup will not get loaded until the first request is sent to them.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic