volatile keyword in Java

volatile keyword is used for a variable.

volatile is used for multithreaded environment.

Each thread in java has it’s own local memory or cache. It stores all the accessible variables in it’s cache for code optimization.

When we mark the variable as volatile , we tell the JVM to never keep the variable in thread’s local cache. Each thread read and write the variable to the main memory. 

Please visit the below post for volatile application in creating Singleton Class in multithreaded Context.

Singleton

Leave a Reply

Your email address will not be published. Required fields are marked *