This week's book giveaway is in the Testing forum. We're giving away four copies of The Way of the Web Tester: A Beginner's Guide to Automating Tests and have Jonathan Rasmusson on-line! See this thread for details.
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?
posted 12 years ago
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.