• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

SingleTon in Cluster Enviroment

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 126
Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic