This week's book giveaways are in the iOS and Features new in Java 8 forums.
We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line!
See this thread and this one for details.
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 Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 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