aspose file tools*
The moose likes Java in General and the fly likes class loader for loading singleton classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "class loader for loading singleton classes" Watch "class loader for loading singleton classes" New topic
Author

class loader for loading singleton classes

srini Raman
Ranch Hand

Joined: Oct 16, 2006
Posts: 33
Hi,
I need to load Singleton classes multiple times.I want to load them using different classloaders .How can I do it? (Even if I create a custom classloader ,I am not able to obtain different references when I initiate the classloader instances using 'new CustomClassLoader()'.I am delegating the control to the parent ClassLoader class in the loadClass() method for loading the class ). If I get different classloader for a class, will the objects created in the loaded class also will use the same classloader?

Thanks,
Srini
Carey Evans
Ranch Hand

Joined: May 27, 2008
Posts: 225

You will get separate classes for each classloader that loads and defines the class, which is not necessarily the classloader on which loadClass() was called. You can check which classloader loaded a class by calling its getClassLoader() method.

The simplest way to load a class multiple times would be to make sure the class is not in your class path, create a new URLClassLoader each time, and use reflection to access the class's fields.
 
 
subject: class loader for loading singleton classes