A volatile variable is basically a keyword  used to provide visibility and handling of variable changes  in multi-threaded programming. This keyword cannot be used with classes and methods, but it can be used with variables. It is simply used to achieve thread safety for variables. When you mark a variable as volatile, all  threads can read its value directly from  main memory instead of the CPU cache, so  each thread gets the updated value of the variable.