WHAT IS THE USE OF VOLTILE VARIABLE IN JAVA

Mayank Tripathi

Total Post:807

Points:4035
Posted by  Mayank Tripathi
Java 
 670  View(s)
Ratings:
Rate this:
  1. Mayank Tripathi

    Post:807

    Points:4035
    What is the use of voltile variable in java

    The Java volatile keyword is used to mark a Java variable as "being stored in main memory". More precisely that means, that every read of a volatile variable will be read from the computer's main memory, and not from the CPU cache, and that every write to a volatile variable will be written to main memory, and not just to the CPU cache.

    The Java volatile keyword guarantees visibility of changes to variables across threads. In a multithreaded application where the threads operate on non-volatile variables, each thread may copy variables from main memory into a CPU cache while working on them, for performance reasons. If your computer contains more than one CPU, each thread may run on a different CPU. That means, that each thread may copy the variables into the CPU cache of different CPUs.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!