Volatile and doubled checked locking in Java
March 16, 2008 Leave a comment
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