Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Real World Example of Singleton Pattern

 
Vineela Devi
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anyone please give me a real world example of using singleton pattern.

Regards,
Vineela
 
Vinny Menon
Ranch Hand
Posts: 62
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vineela,
one real world example would be:
in one of my earlier projects,we had used the business delegate design pattern.i.e.
we had used struts framework and within the action class ,we made call to the business delegate classand from the business delegate class we made the call to the session bean.


we didnt want multiple instances of the business delegate and wanted to control the instance of the Business Delegate.hence we made it a singleton
class.

the flow is like this..

Jsp-->action class-->Business Delegate(Singleton)-->Session Beans-->entity bean-->Database.



hth
cheers
vinny m
 
Reid M. Pinchback
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many services in a J2EE server are arguably instances of the singleton pattern. At any one time only one variation of a specific service will be in use by the server, but different configurations of the server will allow different choices of service. For example, there will only be one global JNDI tree to search (one in the sense that there is a unique root starting point), but the implementation of that JNDI could be something vendor-specific, an external LDAP, Active Directory, etc.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've used them frequently for caches, factories and statistics utilities like a hit counter.
 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread pools, connection pools, registry objects, objects handling user preferences, caches
 
Thomas Hauck
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following page contains several examples of
the Singleton Design Pattern used in the real world.

Singleton Design Pattern
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic