This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes How to control the order in which a servlet instance is created Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to control the order in which a servlet instance is created" Watch "How to control the order in which a servlet instance is created" New topic
Author

How to control the order in which a servlet instance is created

ravisha andar
Ranch Hand

Joined: Feb 25, 2011
Posts: 55
Hi All.

Can anybody please let me know how to control the order in which a servlet instance is created other than <load-on startup>

Thanks
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
I'll just say this: most reasons for why one might want to do this are likely rooted in bad design. So - why do you want to do this?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Tim Moores wrote:I'll just say this: most reasons for why one might want to do this are likely rooted in bad design. So - why do you want to do this?

Indeed! Red flag warning!



[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
That's the best red flag you can come up with?

Here ya go: http://www.google.com/search?q=red+flag+image&hl=en&prmd=imvns&tbm=isch&tbo=u&source=univ&sa=X&ei=13IPT_XSD4_4sgayoPwD&ved=0CCIQsAQ&biw=1227&bih=1000
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Better?



Personally, I like the sign because it better conveys danger!
Vinod Vijay
Ranch Hand

Joined: Sep 13, 2011
Posts: 137

ravisha andar wrote:Hi All.

Can anybody please let me know how to control the order in which a servlet instance is created other than <load-on startup>

Thanks


Use <load-on-startup>, thats more easier


Vinod Vijay Nair
pankaj patil
Ranch Hand

Joined: Dec 19, 2004
Posts: 98
I depends on when you call the servlet .

you can have design of your own like load the instance one after the other.
depending on the order you wanted


Regards,
Pankaj Patil
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

pankaj patil wrote:I depends on when you call the servlet .

No, it most certainly does not.

The container can load the servlets any time it wants in whatever order it wants in the absence of directives to the contrary. There is no guarantee that the container will wait until first request, and that the order will be determined by the order of requests.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18712
    
    8

The obvious questions at this point are:

(1) Why do you need to control the order in which servlet instances are created?

(2) Why is the load-on-startup feature not sufficient for whatever you need?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Yes, the "why?" question has been asked numerous times, but not answered.
 
Don't get me started about those stupid light bulbs.
 
subject: How to control the order in which a servlet instance is created