• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Scope of Singleton

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the scope of singleton object?

Somewhere I read, it depends on the class loader which we use to load it.
In that case, what are the different cases?

Can anyone please help me?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, in Java, a class loaded by different class loaders actually is considered to be different classes. So "only one instance for the class" comes down to "one instance per classloader used to load the class".
 
Srikanth Penta
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What if the Singleton class is loaded by System loader?
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Srikanth Penta:
What if the Singleton class is loaded by System loader?



what Ilja Preuss said is still correct !
The singleton will be a singleton per classloader.
One can still load the class already loaded by the system classloader, from a seperate URL. So, even if a class is loaded by the system classloader, it may be loaded again by some other classloader in the same jvm instance.
[ May 08, 2007: Message edited by: Nitesh Kant ]
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Srikanth Penta:
What if the Singleton class is loaded by System loader?



I don't think there is anything special about the system class loader in this case. Why do you ask?
 
Srikanth Penta
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought System loader is the universal loader for a JVM and don't know that same class can be loaded with diff. url.
 
Let nothing stop you! Not even this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic