Search code examples
javajakarta-eesingletoncluster-computingdistributed-objects

How to Handle Singleton Classes in Distributed Environment


When an Application is Distributed across multiple JVMS my single ton class will have multiple instances at each JVM. I have to generate a Unique ID for this purpose i have to use a singleton pattern class. It is Working fine when in a Standalone Environment. How to make a Singleton pattern in distributed environment so that we can use only one instance ?

EDIT: For my application i need to create userid like

if the name is like Pavan Kumar the userid should be pavankumar if in the system already if this userid exists the userid should be like pavankumar1,pavankumar2 etc......

If the multiple requests for users having same name comes across different servers might result in duplicate id. For this purpose i wanted to use a singleton across distributed environemnt.


Solution

  • I have found a solid answer for this question after a long time. It is possible to implement a Singleton in a distributed environment using AKKA toolkit. Details on how to implement can be found from here http://doc.akka.io/docs/akka/2.3.1/contrib/cluster-singleton.html