Meaningless Drivel is fun!*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes static variables in distributed programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "static variables in distributed programming" Watch "static variables in distributed programming" New topic
Author

static variables in distributed programming

George Fung
Ranch Hand

Joined: Jun 12, 2003
Posts: 98
There may be serveral instances of a servlet running on different JVMs. One of the exam book states we can't use static variables to share the data. Do you know the reason?
siva raju
Ranch Hand

Joined: Oct 10, 2003
Posts: 37
I assume you are talking about distributed apps since you mention different JVMs. Static variables are local to each JVM. So you cant share data between servlets on different JVMs. If you want to share data, you might consider using sessions or other mechanisms like a DB.
For the same reason, you cannot even depend on static variables for storing any data. The container might decide to migrate your session to a new jvm where you will lose all you static vars values unless you take explicit steps with the HttpSessionActivationListener interface.


Siva<br />-----<br />SCWCD 1.4, SCJP 1.4, SCBCD(Preparing), CCNA
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static variables in distributed programming