Each thread has its own
stack, and so its own copy of variables it can access. When the thread is
created, it copies the value of all accessible variables in its own memory. The
volatile keyword is used to say to the JVM "Warning, this variable may be
modified in another Thread". The volatile forces the thread to update the
original variable for each variable.
Showing posts with label volatile. Show all posts
Showing posts with label volatile. Show all posts
Monday, 16 January 2017
Sunday, 15 January 2017
What is volatile keyword in Java?
When we use volatile keyword with
a variable, all the threads read its value
directly from the memory and doesn’t cache it. This makes sure that the
value read is the same as in the memory.
Subscribe to:
Posts (Atom)