• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

ServiceLocator/Singleton as an cache in clustered environment

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Does anyone know any articles or books considering Java/J2EE programming in clustered environment? I have many question in my mind but following is the most relevant.
Is it possible to use ServiceLocator/Singleton as an cache in clustered environment? I should maintain a collection of data in a Singleton class read from database using an EJB. That data could be changed by a Web client in applications' program code. What I have understood is that Singleton classes instances are different in every Clustered node's Web container. So, if this is true, how can I synchronize data if it's changing in one of the clustered node/Web Container?
Or is it possible to use EJB as an cache?
Anyone had this kind of situation...
Br Mik Laan
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Singleton's aren't singletons in a clustered environment. Whether that matters or not depends on what you use them for.
One use of a Singleton is to centralize access to some resources. The "singleness" is not critical, but is used to help with performance or memory or resource usage. It is OK to use this kind of singleton in a cluster, since having different instances on different machines is probably actually what you want, and doesn't affect the behavior.
Another kind of singleton would be one that caches read-only data. Here you want to reduce the overhead of creating/querying/reading the data. You only want to do this expensive operation once, so you cache the data in a singleton. This kind of singleton is also OK in a cluster, since it still meets the expectations (reducing expensive data access).
Another kind of singleton has some cache of read-write data. In this case, everybody that uses the singleton expects to get the correct current state. This kind of singleton, when implemented the traditional way using a static class variable, is bad in a cluster since each node of the cluster will have a different singleton instance, and they will get out of sync as soon as someone writes to it.
But you can still implement a cluster-wide singleton as long as it is backed by something better than a static class variable, like a database.
Probably the best fit for this would be an Entity Bean. The data is probably cached on each cluster node (depends on the app server), backed by a central database, and the app server may even keep the cluster node caches up to date with each other.
 
mik laan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Dave!
Can anyone suggest any books etc. that tell more
about these kind of things in clustered programs.
This is quite interested subject,
Br
Mik Laan
 
I like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic