*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Singleton class  creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Singleton class  creation" Watch "Singleton class  creation" New topic
Author

Singleton class creation

Avinash Tiwari
Ranch Hand

Joined: Sep 20, 2006
Posts: 50
Hi
With plenty of materials around singleton and I guess being the most widely used pattern across all j2ee applications. How do we truly make a class Singleton in distributed architecture.

We have many constraints like cloning , reflection , class loaders , multi threading , double checked locking etc.

Please help out the near to exact way we can have singleton in place.

Thanks,
Avinash

Work hard and rest not till the job is done....
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

The best way to use singleton objects in Java is making the use of Singleton Session Bean (@Singleton). For you to understand how these issues are resolved, study JEE specification of the life cycle of Singleton Session Bean and hows the server providers have settled in clustered environments.
Best Regards.


Fernando Franzini - Java Blog
Avinash Tiwari
Ranch Hand

Joined: Sep 20, 2006
Posts: 50
Thanks for the reply.

Please help out with Singleton on non EJB perspective. That would be helpful.

Thanks
Avinash
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Joshua Bloch in Effective Java book presents the best approach to build objects singleton using enum. But other restrictions you'll need to manually resolve in your project.
Mainak Goswami
Ranch Hand

Joined: May 21, 2006
Posts: 50

You can also go through the dzone article on Singleton. Though it does not cover anything on J2ee specifications but it is more related to core Java.
http://java.dzone.com/articles/singleton-design-pattern-%E2%80%93


------------------------------------
Mainak
idiotechie
------------------------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Singleton class creation
 
Similar Threads
Servlets
what is the use of this " static A a = new A() "
Singleton class for Closing Database Connections .
Difference between in making a class as singletone and
Clarifications/Suggestions in Java