This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

class loader for loading singleton classes

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

Ranch Hand
Posts: 225
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic