2021-02-18 java单例模式

public class SingletonObject {

private static volatile SingletonObject instance;

private SingletonObject() {
}

public static SingletonObject getInstance() {
if (instance == null) {
synchronized (SingletonObject.class) {
if (instance == null) {
instance = new SingletonObject();
}
}
}
return instance;
}
}
posted @ 2021-02-18 15:03  imgax  阅读(75)  评论(0编辑  收藏  举报