----- Original Message -----
From: "Christopher K. St. John" <[EMAIL PROTECTED]>


>  I was trying to be careful to speak in terms of the container,
> not just a single servlet context.

I was trying to find out what happens in a single servlet context.


>  I'm pretty sure every servlet context must have its own classloader.
> Two servlets of the same class in different contexts would definitely
> need their own set of static members. If you're depending on singletons,
> you'd have to take that into account.
>
>  Are we agreeing on this?

Yes. I agree. An excellent discussion of this can be found in a white paper
by Ted Neward at  http://www.javageeks.com/Papers/JavaStatics/index.html


>I'm not sure I read your statement
> correctly.

Let me explain what I was trying to say.  Let us suppose that in a given
servlet context we have two servlet definations. Both of these use the same
servlet class but with different initialization parameters. Hence as per the
specs we will have two servlet instances. My doubt is will there be multiple
copies of the servlet Class. If there is only one copy of the Class then it
will share the static variables. Will this not lead to messing up of the
static variables. Something like a counter to count the no. of hits will be
affected.
I think there will be only copy of the Class because as per the JLS, a
classloader can load a Class only once. When asked again it returns the same
Class.

If my understanding is wrong, can someone pl. correct me.


>  Slight correction to my original post: the servlet is not
> necessarily init()'ed when it's instantiated. You can instantiate
> a servlet object, wait a while, then call init(). You can even
> (I think) throw the servlet object away without ever calling init()
> at all.

As per my reading of the specs 2.2, the destroy method is called only when a
servlet is being taken out from *service * by the container.  I think the
specs assume that the servlet is in service only if the init method executed
successfully( did not throw UnavailableException).

The container does two steps. Loading and instantiation. I think the static
blocks will get executed when the class is loaded. In my opinion it makes no
sense for the container to instantiate a servlet and not call it's init(),
but the specs don't prohibit it.

regds,
Gokul

> -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

Reply via email to