2

Singleton object will create instances per jvm basis. How it works in clustering environment?

What are the alternatives?

Ravindra S
  • 6,302
  • 12
  • 70
  • 108
Raj
  • 475
  • 2
  • 10
  • 18

2 Answers2

2

Technically, you can use Terracotta to cluster the JVM. I think it will guarantee the singleton instance.

But I think it's not what you want. Singletons are just "global state". So you don't need the same instance as long as the state (field values) in it is the same. I don't know how you cluster your application, but I guess you can have cluster-wide data.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
1

One alternative is to not create a Singleton:

http://code.google.com/p/google-singleton-detector/

Google thinks they're a bad idea.

Clustered caching sounds like what you want. Maybe a Terracotta or a Coherence is a better idea.

duffymo
  • 305,152
  • 44
  • 369
  • 561