Geeta Ramani wrote:
>
> Just want to mention that anything that my understanding is that code in the
> init() method is executed *exactly once* when the servlet class is first loaded.
> This may answer your question.
>
You've got to be careful in making statements about the
init() method, there are lots of caveats (that's latin,
is latin allowed? :-)
Normally you don't have to think about any of this, it
just sort of works out (which is a tribute to the spec
writers). However, when something goes wrong, it can get
messy fast...
First off (and I suspect this is what you meant) init()
is called when a servlet instance is instantiated, not
when its class is loaded.
There are a couple of ways that the init() methods of
different servlets of the same class could get called at
the same time. From the 2.3 spec (but applies generally):
It is important to note that there can be more than one
instance of a given Servlet class in the servlet
container. For example, this can occur where there was more
than one servlet definition that utilized a specific servlet
class with different initialization parameters. This can also
occur when a servlet implements the SingleThreadModel
interface and the container creates a pool of servlet
instances to use.
Also, the container can unload, then reload the servlet, so
init() might get called many times over the life of the
container.
Even worse, there can be multiple copies of not just
instances of a servlet class, but multiple copies of the
servlet class itself (and thus multiple copies of its class
static members)
It's best to make as few assumptions as possible...
-cks
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html