Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Singalton in distributed env

 
Deepika Joshi
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
John Kimball
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 449
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Distributed environments, we usually have multiple VMs running, whereas the singleton pattern normally implemented is a per-VM singleton.
 
Deepika Joshi
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all of you for your response.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic