Volatile and doubled checked locking in Java

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: