/*
* ,
*/
public class Singleton {
private static Singleton instance;
public static Singleton getInstance(){
if(instance == null){
return new Singleton();
}else{
return instance;
}
}
}
/*
* 。
*/
public class Singleton {
private static Singleton instance;
public static Singleton getInstance() {
synchronized (instance) {
if (instance == null) {
return new Singleton();
} else {
return instance;
}
}
}
}
public class Singleton {
/*
* , , , ,
* , , , , !
*/
static class SingletonHolder {
static Singleton instance = new Singleton();
}
public static Singleton getInstance() {
return SingletonHolder.instance;
}
}