If you declare a member variable as volatile in Java, does this mean that all object 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 its instance as follows:
private volatile C obj;
whether the reference to the stores objin volatile memory or objdata ( obj.iand obj.c) in the memory volatile?
obj
obj.i
obj.c
volatile
Does flow obj.cand obj.ithread safety provide or not?
JVM, , . , - volatile, , , .
class C { volatile int i = 0; volatile char c = 'c'; }
Re: , , , . @gerrytan Oracle, volatile , , , . ...
if(obj != null) { obj.doSomething(); }
- , , , , obj.doSomething(), obj = null. , synchronized.
obj.doSomething()
obj = null
synchronized
obj volatile.
obj.c obj.i ?
. , .
, . obj.i obj.c ,
class C{ volatile int i = 0; volatile char c = 'c'; }
- Java, , ?
, , volatile Object. , CPU, Heap , . , , , , .
obj.c obj.i ? . , , . , , , , - , , .