单例Singleton完美版本实现:double-check

来源:互联网 发布:mysql gtid复制原理 编辑:程序博客网 时间:2024/05/29 03:17
public class Singleton {    private static Singleton singleton = null;    private Singleton() {    }    public static Singleton getInstance() {        if (singleton == null) {            synchronized (Singleton.class) {                if (singleton == null) {                    singleton = new Singleton();                }            }        }        return singleton;    }}

原创粉丝点击