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?
Joined: Oct 10, 2003
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.