2

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

What are the alternatives?

Ravindra S
  • 5,906
  • 12
  • 67
  • 103
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
  • 572,413
  • 138
  • 1,043
  • 1,132
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
  • 299,921
  • 44
  • 364
  • 552