Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are static objects treated while clustering?

Static objects are initialized only once. Singleton classes are instantiated only once. If we use a singleton in a cluster then it will create multiple instances of singleton in the clusters. So what happens to the static object in a cluster environment? Why this object is not initialized in other cluster servers? or why the objects state doesn't change?

like image 494
karthick Avatar asked Feb 24 '23 07:02

karthick


1 Answers

Static Objects are always in the scope of the ClassLoader (in most cases per JVM) and are not regarded in clustering. If you need a Singleton you have to tell the container to create one. It depends on the nature of your Singleton if it should exist only one per Cluster or once per JVM or once per Classloader.

like image 183
rurouni Avatar answered Feb 26 '23 21:02

rurouni