With JRun 3.x, it depends where the class is, i.e., in which classloader's scope it 
was.  If under WEB-INF/lib or classes, and as long as the WEB-INF/lib or classes 
wasn't in the system classpath (it wouldn't be unless you or someone else explicitly 
added it), then (because there is a separate classloader for each Web app) the static 
variable would have separate instances -- one for each classloader.

On the other hand, if the class having the static var was in $JRUN_HOME/servers/lib, 
$JRUN_HOME/servers/server-name/lib or in any other way in the system classpath, then 
the class is loaded by the JVM's application classloader, and every Web app under the 
server shares the same instance (because the Web app classloader delegates to the 
parent loader -- the JVM's application classloader in this case).

All mysteries can be revealed by calling getClass().getClassloader() and printing out 
the reference.  You can use that technique to see whether you're Classloader is an 
instance of a JRun-specific classloader, or whether it's a Sun implementation, just by 
looking at the name.

As someone else pointed out, the classloader details for Web apps are specified a 
little more clearly in Servlet 2.3.

Scott Stirling
JRun QA
Macromedia

-----Original Message-----
From: Duane Morse
To: [EMAIL PROTECTED]
Sent: 1/28/2002 3:31 PM
Subject: Re: What does the spec say about how servlet contains handle stat ic 
variables in the same class for different web apps?

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