class Singleton{
private Singleton(){
}
private static Singleton sg=null;
public static Singleton getSg(){
if (sg == null) {
synchronized (Singleton.class) {//使用所在类本身充当锁
if (sg == null) {
sg = new Singleton();
}
}
}
return sg;
}
}
JAVA#单例设计模式'线程札记
猜你喜欢
转载自blog.csdn.net/Iverson941112/article/details/85701001
今日推荐
周排行