标签:style blog color java sp div on log bs
方式一:
public class SingletonClass {
private volatile static SingletonClass instance = null;
public static SingletonClass getInstance() {
if (instance == null) {
synchronized (SingletonClass.class) {
if (instance == null) {
instance = new SingletonClass();
}
}
}
return instance;
}
private SingletonClass() {
}
}
注意:这只是JDK1.5之后的Java的解决方案
方式二:
public class SingletonClass {
private static class SingletonClassInstance {
private static final SingletonClass instance = new SingletonClass();
}
public static SingletonClass getInstance() {
return SingletonClassInstance.instance;
}
private SingletonClass() {
}
}
标签:style blog color java sp div on log bs
原文地址:http://www.cnblogs.com/cool5201314/p/4039692.html