This is an example of unsafe publication:
public class MyClass{
public Holder holder = new Holder(42);
...
}
This publication is unsafe because there is not sufficient synchronization and reader threads may see stale value (null);
But in case of static field it is safe:
public static Holder holder = new Holder(42);
Static initializers are executed by the JVM at class initialization time; because of internal synchronization in the JVM, this
mechanism is guaranteed to safely publish any objects initialized in this way [JLS 12.4.2].
To fix the issue that is described in the beginning just add the volatile modifier to the instance field;
public class MyClass{
public volatile Holder holder = new Holder(42);
...
}