Re: Happens before between putting and getting from and to ConcurrentHashMap
Well, "yes, sort of". Your example works for String, because it is immutable. Specifically, there is a happens-before relationship between the constructor's initialization of the final fields of the String and the subsequent publishing store of the result of the constructor. However,
Happens before between putting and getting from and to ConcurrentHashMap
Hello, let's look at: class P { public String x; } ConcurrentHashMap x = new ConcurrentHashMap<>(); new Thread(() -> { // Thread 1 x.put(1, new String("x")); // 1 }).start(); new Thread(() -> { // Thread 2