Consider below scenario, it says if str
is volatile it means any update by any thread accessing str
, will directly update on main stack instead of local Thread cache.
class A{
volatile String str;
volatile B b=new B();
}
class B{
int a;
C c;
}
For b
volatile object, how scenario will work?
I read few links it says only reference is volatile and not the property of object itself, what does that mean, can some one help me with some example as I am finding it little bit difficult to understand.
if reference is synchronized, then how it will help, what is the use of it?