Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • 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.
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!