典型的懒惰单例:
public class Singleton {
private static Singleton INSTANCE;
private Singleton() {
}
public static synchronized Singleton getInstace() {
if(INSTANCE == null)
INSTANCE = new Singleton();
return INSTANCE;
}
}
典型的热切单身人士:
public class Singleton {
private static Singleton INSTANCE = new Singleton();
public static Singleton getInstance() {
return INSTANCE;
}
}
为什么我们不关心与热切单例的同步,而不得不担心与他们的懒表亲的同步?