• Post Reply Bookmark Topic Watch Topic
  • New Topic

statics , singletons, webapps & scope

 
Jeff Gaer
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are statics global to the JVM in J2EE or local to web Applications? If I have a static property in a class, and use the class definition in multiple webapps, will all webapps reference the same instance?
I.e if I have a singleton in a library, and get an instance of it in two different web applications packaged in the same EAR, will it be the same instance?
Does it make a difference if the singleton is part of an library packaged externally to the webapp?
 
Edy Yu
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as your two web apps are runing in the same VM and the singleton is "visible" to other packages, they will us the same instance of the singleton class.
BTW, you can do a test to get the object id of that instance from different packages and see if it is the same.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!