If you declare a member variable as volatile in Java, does this mean that all the object's data is stored in volatile memory, or that the reference to the object is stored in volatile memory?
For example if I have the following class:
class C{
int i = 0;
char c = 'c';
}
If I declare an instance of it as follows:
private volatile C obj;
does that store the reference to obj
in volatile memory, or obj
's data (obj.i
and obj.c
) in volatile
memory?
Does it make obj.c
and obj.i
thread safe or not?
volatile
keyword as storing object in volatile memory, but it ensure read and writes are atomic. docs.oracle.com/javase/tutorial/essential/concurrency/… – Recumbentvolatile
modifier. en.wikipedia.org/wiki/Volatile_memory – Pieria