Sunday, 4 December 2016

What is volatile variable in Java ?


Volatile Variable :

Volatile is a keyword that must be used when declaring any variable that will reference a device register. Volatile variable is used in multi-threading programming.

In multi-threaded programming environment multiple threads are running concurrently and if any thread make some changes to any variable ,then those changes are not visible to others threads ,so to solve this problem volatile variable is used. Volatile variables guarantees that write must be perform before read.

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 threads. What's more, it also means that when a thread reads a volatile variable, it sees not just the latest change to the volatile, but also the side effects of the code that led up the change.



      
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.

This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.



No comments:

Post a Comment