What is Volatile Keyword in Java ?

The volatile keyword guarantees global ordering on reads and writes to a variable. This implies that every thread accessing a volatile field will read the variable’s current value instead of using a cached value.

By marking the variable volatile, the value of a variable is never cached thread-locally. All reads and writes will go straight to main memory of Java.



You May Interest

How Will You Use Other Java Files of Your Application in JSP Code ...

What is String Interning in Java ?

What are the Atomic Operations in Java ?

Why Java Provides Garbage Collector ?

Why We Cannot Create a Generic Array in Java ?