...
Code Block | ||
---|---|---|
| ||
public class Container<K,V> { volatile Map<K,V> map; // ... } |
This also applies to immutable sub-objects by enabling their safe publication, in that, once published, it is impossible to change the state of the sub-object.
Risk Assessment
Failing to use volatile to guarantee visibility of shared values across multiple thread and prevent reordering of statements can result in unpredictable control flow.
...