Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Scope of Singleton

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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.
 
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic