Forums Register Login

When is a Servlet class loaded and instantiated?

+Pie Number of slices to send: Send
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!
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Hi Tarun

Thank you very much. I think I'm very satisfied with your explanation. Thanks!
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1034 times.
Similar Threads
Servlet init method behavior
Compiling jsp to servlet-Concept
Servlet loading
servlet loading
order of execution in java
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:52:00.