• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EAR ClassLoader

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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.!!!:-)
 
reply
    Bookmark Topic Watch Topic
  • New Topic