Does the spec say that this is the required behavior, or is this where one
implementation
can vary from another?  A colleague said that he tried the experiment with
JRun 3.1, running
2 copies of the same application, and a static counter variable that was
incremented only
at startup ended up with a value of 2.

Duane Morse, Eldorado Computing Inc., Phoenix, Arizona


-----Original Message-----
From: Anton Tagunov [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 28, 2002 4:19 PM
To: Duane Morse
Cc: [EMAIL PROTECTED]
Subject: Re: What does the spec say about how servlet contains handle
static v ariables in the same class for different web apps?


Hello Duane!

DM> Does the servlet specification say anything about how the servlet
container
DM> should deal with static variables
DM> in the same class when used by different web applications?  The
potential
DM> problem is having common components
DM> interfere with each other (as far as static variables are concerned)
when
DM> they are used in different web apps running in the
DM> same servlet container.

Not a chance :-)

The same .class file loaded by twice by different classloaders
results in two classes differnt from the JVM point of view.
A class in JVM is designated by
- its name
- the classloader that loaded it

So, if file.class has been loaded by two different classloaders
two different classes appear in the JVM. And each has its own
set of static variables.

And all servlet containers provide separate classloaders for
separate webapps.

I guess that if you servlet container
provides dynamic web reloading (f.e. when it detects that
some .jar has changed its creating date to a later time)
then this is implemented by supplying a new class loader
each time the webapp reloads.

(Hence some people get a
funny problem: they define some class, f.e. class A,
put it into a .jar, put the jar into the WEB-INF
of a webapp. When the webapp runs it create an instance
of A, save it as a session attribute. Then they change some .jar
in WEB-INF/lib, the whole webapp gets reloaded.
While the webapp runs it at some moment get this session attribute,
but it is no longer belonging to class with name A, loaded
by the webapp's classloader!
They get an exception when this object to A!)

DM> Duane Morse, Eldorado Computing Inc., Phoenix, Arizona

Best regards

- Anton
[EMAIL PROTECTED]
[EMAIL PROTECTED]

___________________________________________________________________________
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