What are some recommended approaches to achieving thread-safe lazy initialization? For instance,
// Not thread-safe public Foo getI
The easiest way is to use a static inner holder class :
public class Singleton { private Singleton() { } public static Singleton getInstance() { return Holder.INSTANCE; } private static class Holder { private static final Singleton INSTANCE = new Singleton(); } }