What is volatile keyword in Java?
Printable View
What is volatile keyword in Java?
Volatile Keyword we only where we do not want cache value of this variable and give a action to always read it from main memory. Most important things it cannot be used with method or class, only used with a variable.
Declaring An unstable java variable means: the quality of this variable will never a chance to be cached thread-locally: all peruses Furthermore composes will try straight should "main memory"; right of the variable goes about Likewise In spite of it may be encased to a synchronized block, synchronized on itself.
The volatile keyword could be used on every kind of variable, either primitive or objects!
Fastmailsender
Volatile keywords in the Java are used to stored in the main memory of the Java. Every time the volatile keyword will be read from the computer's main memory. The volatile keyword is guaranteed to work on 32 bit and 64 variables. They used to synchronised by themselves.
The volatile keyword is used when the thread is created, it copies the value of all accessible variables in its own memory. The value of this variable will never be cached thread locally. All the reads and writes will go straight to the main memory.