+ 4

What is volatile keyword?

17th Sep 2016, 6:12 PM
Sadab Khan
Sadab Khan - avatar
5 Réponses
+ 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