During my Java training, I read about volatile keyword, but didn’t get clear understanding. Recently when I wrote a singleton class using double checked locking, PMD code reviewer gave a warning not to use volatile. Later I started exploring on double checked locking issue, here is my observation.

What is volatile?
Generally JVM copies frequently accessed variables into register memory (recollect micro processor subject) for speedy access. Volatile emphasis that always the variable is read from main memory avoid duplicate copies.

Looking for practical example? read the double checked locking issue from the below link.
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html

Leave a comment

I’m Venkat

A passionate software engineer with over 20 years of experience in the tech industry. Welcome to my digital playground where I share my journey through the ever-evolving world of software development and cloud technologies!