class ObjInstance {
//单例
private static ObjInstance oi = new ObjInstance();
private static User user;
private ObjInstance() {
}
public static User getUserInstance() {
if (user == null) {// 无锁判定
synchronized (oi) {
if (user == null) {// 加锁判定
user = new User(1, "zs");
}
}
}
return user;
}
}