This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Singleton Implementation in Distributed Environment" Watch "Singleton Implementation in Distributed Environment" New topic
Author

Singleton Implementation in Distributed Environment

Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 140
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
Ranch Hand

Joined: Jul 26, 2012
Posts: 523
    
    3

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)?
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

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.
 
wood burning stoves
 
subject: Singleton Implementation in Distributed Environment
 
Similar Threads
clustered environment - Singleton class
singleton
Doubts in Clustered server environment
Clustered Singleton
How to use Singleton Design pattern in a Clustered Environment?