Java单例模式的正确写法

无锁
lazy初始化

public class SingleManager {

    private static class Holder {
        private static final SingleManager INSTANCE = new SingleManager();
    }

    public static SingleManager getInstance() {
        return Holder.INSTANCE;
    }

    private SingleManager() {

    }

}

你可能感兴趣的:(Java单例模式的正确写法)