wood burning stoves 2.0*
The moose likes Websphere and the fly likes EAR ClassLoader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "EAR ClassLoader" Watch "EAR ClassLoader" New topic
Author

EAR ClassLoader

leonardo battagli
Ranch Hand

Joined: Aug 28, 2003
Posts: 33
That should be simple!
Now, I have 2 different EAR (1 WAR + some libs each).
Both of them make use of a common library.
Both of them need to use an Object using the singleton pattern.
Now ... when the first EAR starts, the singleton get called and it get initialized perfectly.
Now... when the second EAR starts, the singleton get called BUT it receives the ISTANCE created by the first EAR.
So... I have 1 INSTANCE instead of two!!
The following has been tested on WebSphere 5 with the following:
- Application CLASSLOADER POLICY: MULTIPLE
- WAR CLASSLOADER POLICY: MODULE
Then... what to do?
I am trying to create a new 'application server' for deploying the EAR number two, but it involves more resources (RAM, ecc.).
So what else to do?
Howard Kushner
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 361
Hello Leonardo,
I am afraid that you have discovered on of the fundamental truths regarding basic JVM class loading: once a class has been loaded, it cannot be loaded again by another class loader.
I would like to understand a bit more about what motivates you to require two separate singletons in the same app server, but I can offer a bit of advice for now, until such time as you post again.
As you are obviously aware, the option exists to have another application server, and as you correctly note, additional resources will be needed.
On the other hand, you might consider another approach. I have discussed your problem with a colleague, and as a result of our discussion I have coined the term doubleton. I see a doubleton as a way of providing static access to two singletons.
If you would consider an analogy, it's kind of like you share a home with a roommate and you can share the same kitchen with your roommate, but you each want your own bathroom.
Anyway, I hope that you can resolve this difficulty, and if you have any additional questions, please feel free to post here or send me a private message. I must admit that I am intrigued.
I wish you the very best of luck, so hang in there, and make it work.


Howard Kushner<br />IBM Certified Enterprise Developer - WebSphere Studio Application Developer V5.0<br />IBM Certified Advanced System Administrator - WebSphere Application Server V5.0<br />IBM Certified Solution Developer - Web Services with WebSphere Studio V5.1<br /><a href="http://www.amazon.com/exec/obidos/tg/detail/-/1931182108/" target="_blank" rel="nofollow">Developing J2EE Applications with WebSphere Studio</a> my Certification Study Guide for IBM Test 287
Mahesh Chalil
Ranch Hand

Joined: Jan 24, 2002
Posts: 147
Yes, When we use the word Singleton "it means a single instance in a JVM", so if 2 applications in a single JVM needs separate instance of the same class, it should not be called as "Singleton".
My 2cents.
leonardo battagli
Ranch Hand

Joined: Aug 28, 2003
Posts: 33
Originally posted by Howard Kushner:
Hello Leonardo,
I am afraid that you have discovered on of the fundamental truths regarding basic JVM class loading: once a class has been loaded, it cannot be loaded again by another class loader.
I would like to understand a bit more about what motivates you to require two separate singletons in the same app server, but I can offer a bit of advice for now, until such time as you post again.
As you are obviously aware, the option exists to have another application server, and as you correctly note, additional resources will be needed.
On the other hand, you might consider another approach. I have discussed your problem with a colleague, and as a result of our discussion I have coined the term doubleton. I see a doubleton as a way of providing static access to two singletons.
If you would consider an analogy, it's kind of like you share a home with a roommate and you can share the same kitchen with your roommate, but you each want your own bathroom.
Anyway, I hope that you can resolve this difficulty, and if you have any additional questions, please feel free to post here or send me a private message. I must admit that I am intrigued.
I wish you the very best of luck, so hang in there, and make it work.

I solved my problem using CLASSLOADER MODE: PARENT_LAST instead of PARENT_FIRST.
but I have to really understand why this happens yet.
Let's talk about the problem I have:
I have an object (called AutoUpdateProperties) dedicated to reading properties files (Such files storing key-value pairs).
To avoid having multiple instance of this object I thought of 2 solutions:
FIRST:
- create an instance of the object and the store it in the SERVLET CONTEXT
- make each object that needs to use the AutoUpdateProperties instance asking for it to the SERVLET CONTEXT
this solutions works for each WAR module but it lacks in this:
Each time I change the property file I have to RE-STORE the istance in the SERVLET CONTEXT
SECOND:
- create a singleton so to have 1 single instance of it
- make each object that needs to use the AutoUpdateProperties singleton instance refer to the single istance inside a WAR module.
To reach an end point I understand this is not a SINGLETON, since I have 3 instance of that object for my unique and only application server, instead I want only 1 istance PER WAR MODULE, how should it be called?
thks in advance
Leonardo
Mahesh Chalil
Ranch Hand

Joined: Jan 24, 2002
Posts: 147
"instead I want only 1 istance PER WAR MODULE, how should it be called"
Just to solve this problem in an easy tricky way, can't your Factory which is creating this instance of your "singleton" class, handle this logic based on Web context? May be sounds foolish.!!!:-)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: EAR ClassLoader