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

What are the Thread-safe Classes in Java Collections Framework ?

What is the Importance of hashCode and equals Methods in Java ?

What is the Use of Interceptor Design Pattern in Java ?

How Will You Include a Static File in a JSP Page ?

What are the Situations in Which You Choose HashSet or TreeSet in ...