What is volatile keyword? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 4

What is volatile keyword?

17th Sep 2016, 6:12 PM
Sadab Khan
Sadab Khan - avatar
5 Respostas
+ 2
thanks all
17th Sep 2016, 7:08 PM
Sadab Khan
Sadab Khan - avatar
+ 1
By declaring a variable volatile, you indicate that a variable's value will be modified by different threads. Incidentally, its value will never be cached thread-locally, and access to the variable acts as though it is enclosed in a synchronized block, synchronized on itself.
17th Sep 2016, 6:52 PM
Zen
Zen - avatar
+ 1
Declaring aĀ volatile java variable means: The value of thisĀ variablesĀ will never be cached thread-locally: all reads and writes will go straight to "main memory"; Access to theĀ variableacts as though it is enclosed in a synchronized block, synchronized on itself.
17th Sep 2016, 6:55 PM
Hekanksh Gohel
Hekanksh Gohel - avatar
+ 1
you all is collect
18th Sep 2016, 4:09 PM
Sadab Khan
Sadab Khan - avatar
0
The count variable is declared as volatile. The copy of volatile variable is stored in the main m/r, so every time a thread access the variable even for reading purpose the local copy is updated each time from the main m/r. The volatile variable also have performance issues.
17th Sep 2016, 6:59 PM
sabreen anjum
sabreen anjum - avatar