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


JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Singalton in distributed env" Watch "Singalton in distributed env" New topic
Author

Singalton in distributed env

Deepika Joshi
Ranch Hand

Joined: Feb 24, 2009
Posts: 268
Please share view or link for some information about
Singalton in distributed env, someone asked me about this and I had no anwer.
I know Singalton, and would like to knwo if it is possible to implement Singalton in distributed env.
If yes, please drop few lines or link for same.

Thanks.

Posting same quest 3rd time, hopefuly won't get invisible because of new software.

Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
The Singleton pattern is not an effective object-oriented design pattern and is rarely appropriate in a distributed environment. Surely, it can be implemented but would typically become a potential bottleneck in an enterprise software system. Moreover, there are usually more effective ways to design an application without a Singleton.

Singleton is an easy thing to teach and is very simple. So, this is typically the main pattern taught in academic programs by professors who have very little practical experience in object-oriented software design.

Singletons should be avoided in object-oriented software systems. This is true whether they are used in a distributed environment or executed in an application on a single machine.
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Deepika Joshi wrote:
I know Singalton, and would like to knwo if it is possible to implement Singalton in distributed env.

It's not impossible, but do you really want it?
Machine A can have a singleton object SingA, and other machines can get remote proxy of SingA.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
John Kimball
Ranch Hand

Joined: Apr 13, 2009
Posts: 96
Not to mention he's glossing over the fault tolerance logic you have to write.
When server A goes down, who claims the resource and how will the other servers know?

You do need this from time to time, but it's really a solution of last resort.

Anyway, the short answer is you can't because you have multiple JVMs & classloaders.
Maybe there's some custom JVM out there we you can, but this certainly wouldn't be standard.

Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

In Distributed environments, we usually have multiple VMs running, whereas the singleton pattern normally implemented is a per-VM singleton.


http://muhammadkhojaye.blogspot.com/
Deepika Joshi
Ranch Hand

Joined: Feb 24, 2009
Posts: 268
Thanks to all of you for your response.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
You are welcome!
 
GeeCON Prague 2014
 
subject: Singalton in distributed env