Win a copy of Learning Java by Building Android Games this week in the Android 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
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Some examples of Singleton classes from Java API  RSS feed

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

This was the example from me in a training session. I was the trainer and explaining singleton class in multi-threaded environment to batch of 20 new joiners and someone ask me- is there some readily available singleton classes in java - api? And i was like..hmm and bla bla?
Can someone help me..
 
Saloon Keeper
Posts: 9376
181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't quickly think of one off the top of my head.

I hope you explained to your students that mutable state that is globally accessible is a really bad idea, and not to be emulated.
 
Ranch Hand
Posts: 89
Eclipse IDE Hibernate Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would think of a Runtime class in the java.lang package.
 
Marshal
Posts: 60737
189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are lots of enums. Since all their instances are intentionally distinct, that is similar to Singletons.
System class. No, that isn't a singleton because it always has exactly 0 instances.
 
shivanyy gupta
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:There are lots of enums. Since all their instances are intentionally distinct, that is similar to Singletons.
System class. No, that isn't a singleton because it always has exactly 0 instances.


As per my understanding, Enums are  a way to create Singleton classes, not itself it is Singleton.
 
Ranch Hand
Posts: 59
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The logging classes (log4j, etc) are Singleton.

The database connection classes are singleton.

Thread pooling classes are singleton.
 
Marshal
Posts: 6078
418
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ravi Desigan wrote:The logging classes (log4j, etc) are Singleton.


Since when they started bundling it with Java API?
 
Ravi Desigan
Ranch Hand
Posts: 59
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh I see! My bad.
 
Stephan van Hulst
Saloon Keeper
Posts: 9376
181
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even then, they're not singletons (but they are "instance limited", which is basically the same pattern).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!