• Post Reply Bookmark Topic Watch Topic
  • New Topic

Some examples of Singleton classes from Java API  RSS feed

 
Ranch Hand
Posts: 33
  • 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: 8225
144
  • 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: 78
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: 57260
175
  • 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: 33
  • 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: 5230
364
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: 8225
144
  • 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).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!