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