Does JVM guarantee to cache not volatile variable? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Does JVM guarantee to cache not volatile variable? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

Does JVM guarantee to cache not volatile variable ?

Can a programer depend upon on JVM to always cache non-volatile variables locally for each thread.

Or JVM may or may not do this, thus a programer should not depend upon JVM for this.

Thanks for the answers in advance.

Answer

No. The JVM doesn’t guarantee “caching” of non-volatile fields. What implementations of JVM guarantee is how volatile fields should behave. Caching of fields is non-standard (unspecified) and can vary from JVM to JVM implementation. So, you shouldn’t really rely on it (even if find out, by some way that some data is being cached by a thread)

We are here to answer your question about Does JVM guarantee to cache not volatile variable? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji