Volatile

This is Fifth Article in Series of Articles on Java 8 Concurrency Tutorial.

In this quick article, we’ll focus on a the concept of volatile keyword in the Java language.

Every read of a volatile variable will be read from the RAM so from the main memory and not from cache. Usually variables are cached for performance reasons.

Using volatile variables reduces the risk of memory consistency errors, because any write to a volatile variable establishes a happens-before relationship with subsequent reads of that same variable. This means that changes to a volatile variable are always visible to other thread.

Volatile Keyword Example
1
private static volatile int COUNT = 0;
Share Comments