jQuery in Action, 3rd edition
The moose likes Distributed Java and the fly likes Singleton Implementation in Distributed Environment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Singleton Implementation in Distributed Environment" Watch "Singleton Implementation in Distributed Environment" New topic

Singleton Implementation in Distributed Environment

Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 141
We are having a web application deployed on tomcat but now we are going to deploy the same web application on different servers i.e. in clustered environment. We do have some classes implemented as Singleton. So, in clustered environment, the singleton functionality is going to break. Please let me know the feasible solution so that there will be just one instance every time for the object in the clustered environment.
Stevens Miller

Joined: Jul 26, 2012
Posts: 853

Tell us a bit more about your situation, please. What do the singletons do that require they be singletons? Can you delegate that part to a central server, or would that violate your design requirements (or be too much for a central server to handle)?

In the other disciplines, we rise by standing on each others' shoulders. In computer science, we do it by standing on each others' toes.
Pat Farrell

Joined: Aug 11, 2007
Posts: 4659

While this is a bit late, you really should not be using Singletons. You have found one of the reasons, in complex environments, you can't be sure that they are really singletons.

Additionally, Singletons are simply global wads of data, which totally breaks encapsulation. This makes unit testing much harder than systems without singletons.

In nearly all cases, the use of Singletons is a mistake and can be avoided simply by deciding not to use them.
I agree. Here's the link: http://aspose.com/file-tools
subject: Singleton Implementation in Distributed Environment
It's not a secret anymore!