单例模式线程安全的实现

大家的写法

public class Single {
    private static class Holder {
        static Single instance = new Single();
    }

    private Single() {
    }

    public Single getInstance() {
        return Holder.instance;
    }
}

皮一下的写法,优化后是上面的

public class Single {
    private static Single instance;

    static {
        instance = new Single();
    }

    private Single() {
    }

    public Single getInstance() {
        return instance;
    }
}