Double Check Lock(双重检查锁):
public class kongjiaoshi {
private static kongjiaoshi kongjiaoshi = null;
public static kongjiaoshi getInstance() {
if (kongjiaoshi == null) {
synchronized (com.example.liang.siruanbei.utils.kongjiaoshi.class){//注意这里括号里面写的是.class,而不是.this
if (kongjiaoshi == null) {
kongjiaoshi = new kongjiaoshi();
}
}
}
return kongjiaoshi;
}