wood burning stoves 2.0*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Singleton in clustered environment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Singleton in clustered environment" Watch "Singleton in clustered environment" New topic
Author

Singleton in clustered environment

Nizar Syed
Greenhorn

Joined: Jan 06, 2008
Posts: 2
Hi,
Please help me to clarify below questions.

1. Only one instance of the Singleton class will be created per container. if the application is deployment in clustered distributed environment, my understanding is that for each cluster an instance of singleton class will be created. is my understanding correct? if so how to make to sure a single instance of singleton class is created across clusters.
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
Nizar Syed wrote:Hi,
Please help me to clarify below questions.

1. Only one instance of the Singleton class will be created per container. if the application is deployment in clustered distributed environment, my understanding is that for each cluster an instance of singleton class will be created. is my understanding correct? if so how to make to sure a single instance of singleton class is created across clusters.

Yes, many application servers provide distributed objects supports to allow for cluster wide objects.
Stijn De Mulder
Greenhorn

Joined: Apr 09, 2014
Posts: 3

Hi,

Your assumption about the singleton pattern is correct. There will be one instance per "deployed" application. So when you have a clustered setup (multiple deployed instances of the same application to provide load balancing) the singleton pattern isn't really valid.

Of course some application servers support cluster wide instances, but you will be creating a dependency on your deployment model. This implies that each node in the cluster knows about the other node, which is a true cluster, but in most cases they simply don't know about each other. It's much simpler to setup.

What is your end goal by using this pattern? Have you considered some some form of persistence (e.g a database?)


Follow me

Learn Design Patterns
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1006
    
    3
As long as we're talking about patterns...

In a distributed system, the Singleton could be implemented using the Proxy pattern. One of the uses of the Proxy pattern is for when client objects want to access an object that is on a different server. The clients access the Proxy using the same interface as for the real Singleton object, and the Proxy handles the coordination between the local objects and the remote (real) Singleton.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Singleton in clustered environment
 
Similar Threads
clustered environment - Singleton class
What are all the Common Servlet Programming practises for Clustered Environment?
singleton
Singleton in Cluster
Singleton and Thread Safety