‘volatile’ keyword in java programming
‘ volatile ’ is a keyword used in java. It provides the changes that can be visible across the multiple threads . Most recent value is applicable for all threads. Features: Visibility across the multiple threads. Even though Caching, atomicity cannot be done, it is light weight and overhead is reduced. It makes latest value is read/written is visible. Use ‘volatile’ keyword when the following condition occurs… Multiple threads access the same variable for reading and writing. Singleton patterns are used. Thread safety is needed. Java program using ‘volatile’ keyword: class SFlag { private volatile boolean f_run = true; public void stop() { f_run = false; // this statement makes this variable visible to all threads } public void doIt() { ...