• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

When is a Servlet class loaded and instantiated?

 
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm passed through the Servlet chapter in HFSJ but I think I didn't get how the Servlet class is first loaded. I get the impression that the idea of the Servlet class being loaded on the first deploy/startup of the container is somehow vendor-dependent.

Also, is possible for the init() method not to be called when the Servlet is instantiated? Thanks!
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AFAIK, the specification doesn't mandate when the container should load a servlet ( unless using <load-on-startup> ).

So the container can load and instantiate the class whenever it needs to. By using <load-on-startup>, you can be sure that your servlets will be loaded when the app is starting up and be available. Otherwise, the order is pretty much random and on a need-to basis. A servlet may be ready and waiting for requests, or it may be loaded and initialized only when a request comes for it.

And I'm not very sure about this but yes, I don't think it's necessary for the init() to be called immediately when the servlet is instantiated. But it must be called before the servlet can service any requests.
 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tarun

Thank you very much. I think I'm very satisfied with your explanation. Thanks!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic