Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

clustered environment - Singleton class

 
kri shan
Ranch Hand
Posts: 1462
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the clustered environment, how Singleton class behaves ?
 
Prasanna Ram Rambhatla
Greenhorn
Posts: 10
 
vu lee
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps, another way to do this is to designate a server within a cluster to host the singleton instance. Other servers contains just a remote proxy which access the singleton on this server. Synchronization is taken care in a single JVM.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you describe your requirements a bit more? A lot of times a single instance per JVM is fine. For example, we cache some things we get from the database. Each server has its own cache, no problem.

In one case we have to synchronize the caches so all machines have the same content. The vendor framework uses JMS pub-sub to let all machines know about changes. I gotta ask them some day how they handle a machine that joins the cluster late, like maybe we crash and restart one.

If you really, truly require one instance per cluster you'll have to get into some kind of distributed stuff, worry about a hot standby in case the one machine in the cluster that has the single instance goes away. I'd be tempted to use a database for any state with those requirements.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic