We often use volatile
to ensure that a condition variable can be visible to every Thread.
I see the volatile
fields are all primitive type
in code so far.
Does object
field has this problem? For example:
class a {
public String str;
public List list;
}
If there are some threads which will access str and list, must I add 'volatile'?
I guess each access to Object
will get directly from Heap
, and the Object
will not be cached like primitive type.
Is that right?