Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Singleton class creation

 
Avinash Tiwari
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Avinash Tiwari
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.

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

Thanks
Avinash
 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 52
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic