Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

singleton

 
Raj Joe
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are singleton classes managed in a clustered environment
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic