File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Singleton in clustered environment

 
Nizar Syed
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 989
9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?)
 
Ryan McGuire
Ranch Hand
Posts: 1048
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic