• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static variables in distributed programming

 
George Fung
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic