You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by John Blanco <jb...@tvmax.net> on 2003/08/17 19:32:21 UTC

Tomcat and Static Variables

	I've got a book (extra credit to who can name it) 
which uses a Counter servlet as an example of how 
servlet containers handle static variables.

	It claims that aliases (I may be wrong on this, it's 
hard to decipher the difference between JWS and Tomcat 
lingo) will create different instances to the target 
Servlet, but static variables are recognized.  So 
access to one servlet instance might result in:

	My Counter = 5, Global Counter = 8

	While access to the other counter might have given 
you:

	My Counter = 4, Global Counter = 8

	The global counter would be a count for the two 
instances combined (via the *static* field) and the 
"my" counter would be for the instance via a stanard 
fiield.

	I've tried pointing to the same WebApp via two 
different <Context>'s, but the two apps are treated as 
completely separate, and the static variable doesn't 
hold.  This is correct...two contexts should never 
interfere.

	The question is how I can replicate the above behavior 
so static variables are spanned across more than one 
instance?  Can anyone point me at a Tomcat scoping 
document?

-- 
	- John Blanco
	- Code Guru @ Rapture In Venice
	- http://members.bbnow.net/jblanco

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org