/**
* @author :corey
* @date :Created in 2019/7/10 15:47
* @description:防止单例对象通过反射技术继续创建实例
* @modified By:
* @version:
*/
public class SingleObjcet {
private static SingleObjcet singleObjcet;
private static volatile int count;
private SingleObjcet() {
synchronized (SingleObjcet.class) {
if (count > 0) {
throw new RuntimeException("SingleObjcet 实例已经存在");
}
count++;
}
}
public static SingleObjcet getInstance() {
if (singleObjcet == null) {
singleObjcet = new SingleObjcet();
}
return singleObjcet;
}
}