This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Two war files in a single ear file and each war files has a static variable  RSS feed

 
Suresh Panneer Selvam
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two war files in a single ear file and each war files has a same static variable. ear is running in single JVM. what is static variable behavior? Will it create separate install for each war or will there single static instance and will share both war files?

Thanks
Suresh Panneerselvam
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37234
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suresh,
How do they have the same static varaible? Is it in the same class? If so, it can't be in both wars. It can be in a jar used by both wars.
 
Pierre-Hugues Charbonneau
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Suresh,

Jeanne is correct.

In summary:

* Default behaviour for application server *

For 1 EAR file with 2 WAR files within same VM, the class loader tree looks like this:

1. System class loader (JDK and application server libraries)
2. Parent class loader (EAR file)
2.1 Child class loader 1 (WAR file #1)
2.2 Child class loader 2 (WAR file #2)

- Static variable defined within code at system class path is visible for everyone
- Static variable defined within EAR file itself e.g. via jar file is visible by both EAR code and both WAR file #1 & #2
- Static variable defined within WAR file itself is only visible to WAR file scope

** Note that each application server provides tuning to override the default behaviour ex: WAR file can override / preferred any class found within parent class loader **

Regards,
 
Suresh Panneer Selvam
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne & Charbonneau for detailed explanation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!