• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

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.
 
Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic