Clemente Dani wrote:
>
> But what about executing the init() method when the servlet
> was already loaded?, why does this happen?
>
Servlets can be unloaded and then reloaded at any time.
The lifecycle goes something like:
init() --> service() --> destroy() --> init() --> ...
I'm not talking about the container getting shut down,
or the code changing and being reloaded, I'm talking
about normal operation.
Just as an example: a servlet container is free to
unload your servlet if it hasn't been used for a
while. Maybe it wants to make room for other servlets
that are getting used a lot. So it calls destroy() and
unloads your code. Then, when the next request comes
in for your servlet, the container reloads it, calls
init(), and you're back in business.
There (used to be?) some CGI-based hacks that
actually ran the servlet through it's entire lifecycle
on every single request. A little extreme, but
perfectly legal according to the spec.
Assuming that servlets are "always on" is one of
the reasons people mistakenly assume that they can
do things like run socket servers in background threads
from a servlet. Well, you can do it, but what if the
container decides to swap out your servlet for a couple
of hours?
I'm not sure if your container is actually doing
that, but it's something to consider.
Another possibility is that you're using the single
thread model, which would result in multiple copies
of your servlet getting started up. (But that wouldn't
give me an excuse for a quick rant :-)
--
Christopher St. John [EMAIL PROTECTED]
DistribuTopia http://www.distributopia.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets