• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

singleton

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are singleton classes managed in a clustered environment
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With the typical singleton implementations - a static variable holding a reference to The Only Instance - you'd get at least one per JVM, maybe more if the class with the static variable got loaded by multiple ClassLoaders. Usually that's ok. Most of my singletons are read-only caches intended to reduce the number of trips to the database or some remote source and one query per JVM is still much better than one per web page request.

But singleton is a pattern, not an implementation, and it might be life and death critical to you to make one instance per cluster with some kind of inter-server communication. That is pretty difficult, especially if you want any kind of failover, but I've definitely seen it done.
[ October 15, 2004: Message edited by: Stan James ]
 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic