It's not a secret anymore!
The moose likes Java in General and the fly likes Different ClassLoaders loading Singleton class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Different ClassLoaders loading Singleton class" Watch "Different ClassLoaders loading Singleton class" New topic

Different ClassLoaders loading Singleton class

Saurabh Tandon

Joined: Oct 03, 2001
Posts: 1
I have a class based on Singleton pattern which is called by a RMI Server and another java class. The RMI Server loads the class using a class loader and the normal java class by another class loader, so in the end I have two instances of the same class, can any one suggest some work around for this problem I want only one instance of my class. I have thought of writing my own class loader is it a good way (if yes, what are pitfalls for the class loader I need to take care).
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
okay am not too clear about the question but i was just wondering..
if the class exists in the classpath of the rmi server in the same m/c then the am not so sure if 2 instances of the singleton can exist int he same vm that started the rml server in the first place.
Are you talking about a case where the class is loaded by another vm and rmi server loads it by doing a lookup and then loads the same class from within itself??
I agree. Here's the link:
subject: Different ClassLoaders loading Singleton class
It's not a secret anymore!