SCENARIO:

* one running instance of Tomcat, whose $CATALINA_HOME is c:/tomcat

* multiple Struts-using webapps, each developed separately using Netbeans or Forte, 
autodeployed into that one instance of Tomcat via .war files copied to 
c:/tomcat/webapps.

* ALL classes needed by the webapp and developed by me are in its respective 
WEB-INF/classes or libs directory, and ABSENT from any location common to all webapps 
running under that instance of Tomcat ($JAVA_HOME/jre/lib/ext, $CATALINA_HOME/common, 
$CATALINA_HOME/shared, etc)

* Instead of Action, all of the webapps use com.foo.MyAction, which extends Action. 
Each webapp has its own copy of MyAction.class in its respective 
WEB-INF/classes/com/foo directory, as well as its own copy of the Struts jarfiles in 
WEB-INF/libs (which probably gets unwrapped and repackaged by Netbeans/Forte when it 
creates the .warfile)

And now, where things potentially get ugly...

* MyAction has a few static class variables that get treated like site-wide global 
constants. It assumes that NO OTHER WEBAPP running in a different context path of the 
same Tomcat instance can/will ever see them.

Is this a valid assumption? Do the relevant specs for Servlets, webapps, and/or Java 
classloading GUARANTEE that each context is a sandboxed private universe relative to 
all other webapps running on the machine (at least insofar as classes loaded from 
WEB-INF/classes or WEB-INF/libs are concerned), or would a servlet container and/or 
JVM be perfectly within its rights to examine MyAction.class, determine that two or 
more of the webapps are really using the exact same class, and share a single 
initialized class among ALL of them (with catastrophic results)?

I'm slightly paranoid, because I vaguely remember having a problem with this exact 
issue last February/March. I don't remember exactly, but I was using some 4.0 release 
of Tomcat 4, 1.4.0_x j2sdk, and the last stable daily build (circa mid-January 2002, I 
believe) of Struts available before 1.1b1 officially came out. The good news is that I 
haven't been able to replicate what I think I remember happening with Tomcat 4.1.18, 
j2sdk 1.4.1_03, and Struts 1.1b2, but I'm not sure whether that's due to random good 
luck at the moment, or whether it's The Way Things Are Supposed To Work (but Possibly 
Didn't last year). I'll admit that any problem I might have had last year might have 
been due to some other issue entirely (I knew a LOT less about Struts, and Tomcat for 
that matter, than I do now, and might very well have misconfigured something else so 
badly that it caused it instead, or badly misinterpreted what I thought I was seeing).

So... is it OK to use static class variables in classes extending Struts' Action class 
as site-wide global constants, or is it a Bad Thing, or maybe even Utterly Taboo?

Reply via email to