What are some recommended approaches to achieving thread-safe lazy initialization? For instance,
// Not thread-safe
public Foo getI
If you use lombok in your project, you can use a feature described here.
You just create a field, annotate it with @Getter(lazy=true) and add initialization, like this:
@Getter(lazy=true)
private final Foo instance = new Foo();
You'll have to reference field only with getter (see notes in lombok docs), but in most cases that's what we need.