Search code examples
javasingletonwebspherewarear

java: Websphere Singleton existing in multiple EAR's WARs?


Assuming that I had a Websphere 6.1 server running with this configuration:

  1. Multiple class loaders
  2. Parent-first delegation

This server has two EARs.

EAR1 has WAR1. WAR1 lazy instantiates DummySingleton A.
EAR2 has WAR2.

WAR2 needs a DummySingleton. Does it instantiate it's own DummySingleton B or does it use WAR1's DummySingleton A?

Second question -

Using any combination of these configurations does WAR2 use DummySingleton A?

  1. Single class loader
  2. Multiple class loaders
  3. Parent first delegation
  4. Parent last delegation

Solution

  • I believe the only option in WebSphere 6.1 in which the same instance of DummySingleton A, loaded by either web module, is if you move the jar containing class DummySingleton into a WebSphere Shared Library that is assigned/used by both EAR1 and EAR2. If you also keep class DummySingleton in either EAR (e.g. if for some reason you don't remove the jar, you just copy it) then any EARs containing the class as well would need Parent-first to ensure they reference DummySingleton from the shared / common classloader of the WebSphere Shared Library and not from the class file they contain.