educative.io

Educative

Static Instances holding state

What do you mean by Static Instances in a Class? I cannot figure it out. You mean objects holding states? or you mean sessions? would you provide an example or dig a little deep into this? thanks.

@Javier

In object-oriented programming, the instance variables hold object state in them. Static variables moreover hold state that spans across multiple objects. They generally hold state per classloader. Now, if the instance running that classloader goes down all the data is lost. Whatever data static variables hold it’s not application-wide.

For this reason, distributed memory like Redis, Memcache etc. is used to maintain a consistent state application-wide. When writing applications for distributed systems it’s a good practice to avoid using static instances in the class.

These resources will give you further insights into this:

Functional Programming Pdf

Why functional programming is advantageous for distributed systems - Quora

1 Like

This also confused me. I feel like state is what you mean rather than static? All state is lost if a server goes down, not just static variables. (Presuming we’re talking about the Scalability chapter)