• Post Reply Bookmark Topic Watch Topic
  • New Topic

SingleTon in Cluster Enviroment  RSS feed

 
Suresh Kumar Rajendran
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

If i implement singleton class in cluster environments, each environment would have JVM so can i get single instance for each environment (or) only instance for all clustered environments. How it works could please explain..
 
Nitin Dubey
Ranch Hand
Posts: 126
Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are not updating the state of Singleton object then there shouldnt be a problem with multiple instances across different nodes. Assuming that all the nodes will have identical Singleton objects in all cases. However, if the state of singleton object is changing there are multiple ways to solve it. Each one has its own pros and cons. It will depend what all you have and how you can use it. Some might be an overkill some may be really helpful.

-- If you have money opt for solutions like Terracotta

-- Use distributed cache solutions like memcached. You may build your own. The singleton objects will be kept out of JVM in another JVM/process and can be used from that place. This solution can boost the performance of the application as lot of data can be cached out of JVM.

-- Serialize the state in database and fetch from db everytime you refer the object. Preferred if you have less time, control over the application and lightweight objects

-- If you have messaging middleware, every JVM may have its own copy and whenever anything changes, publish the new state/delta over topic and update other singleton objects. Publishing the message will be in the same transaction, but consumption is out of your control. If you are okay with this delay then this approach is good.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!