package com.heiheihaxi.demo.pojo;
/**
* @Author: heiheihaxi
* @Date: 2020/2/12 15:20
*/
public class SingleDog {
private static SingleDog singleDog = null;
private SingleDog(){}
public static SingleDog getInstance(){
if (null == singleDog){
// 为了测试多个线程获取的是否为同一个对象而增加的等待时间
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (SingleDog.class){
if (null == singleDog)
singleDog = new SingleDog();
}
}
return singleDog;
}
}