• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple Class Loaders In Same JVM  RSS feed

 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a singleton class that holds the cache, and it works just fine when accessed by regular classes. However, if it's accessed from an EJB, it looks like a different classloader is in play -- it doesn't see that the signgleton was created so it creates a second copy of that singleton instead. The entire application is packaged as an EAR with the EJB inside, and it runs under Weblogic.

My question is, is there a way to force the app server (Weblogic specifically) to use the same classloader for EJBs and the common classes?
 
Steve Simon Joseph Fernandez
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

WLS will use a single application classloader for an application packaged as an EAR. Refer WebLogic Server Application Classloading

If you've added your JAR file containing the singleton to your classpath, then it will get loaded by a different classloader - the system classloader; since the classloaders use a delegation model while working. Hope this helps.

_steve.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using singletons is usually more trouble than they are worth in an EJB application. It isn't just a matter of classloaders for a single EAR file. What happens, for instance, if the EJB Server should choose to distribute the EJBs? They would be running in multiple JVMs, so how many singletons do you have and how do you keep the caches simultaneously up to date?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!