Consider this publication of a HashMap. Thread A runs publish(); thread B later observes config != null and reads config.get("k"). What guarantee does the volatile write/read on config provide about the map's internal contents?
class Cfg {
static volatile Map<String,String> config;
static void publish() {
Map<String,String> m = new HashMap<>();
m.put("k", "v"); // plain write
config = m; // volatile write
}
}