线程安全懒汉单例一般继续双检查,检查-》加锁-》检查-》构建
public class Problem02 {
private Problem02 singleton = null;
private Problem02() {
}
public Problem02 getSingleton(){
if(singleton==null){
synchronized (Problem02.class){
if(singleton==null){
singleton = new Problem02();
}
}
}
return singleton;
}
}
源码: 剑指offer4J