How Volatile in Java works ? Example of volatile keyword in Java

How to use Volatile keyword in Java What is Volatile variable in Java and when to use Volatile variable in Java is famous multi-threading interview question in Java interviews . Though many programmer knows what is a volatile variable but they fail on second part i.e. where to use volatile variable in Java as its not common to have clear understanding and hands-on on volatile in Java. In this tutorial we will address this gap by providing simple example of volatile variable in Java and discussing some when to use Volatile variable in Java. Any way Volatile keyword in Java is used as an indicator to Java compiler and Thread t hat do not cache value of this variable and always read it from main memory . So if you want to share any variable in which read and write operation i...