class LaySingleton{
public static LaySingleton instanle = null;
public LaySingleton() {
// TODO Auto-generated constructor stub
}
public static synchronized LaySingleton getinstance(){
if(instanle == null)
{
instanle = new LaySingleton();
}
return instanle;
}
}
//餓漢式,每次都創建,不需要加synchronized 天生線程都安全的.
class LaySingleton{
public static LaySingleton instanle = new LaySingleton();
public LaySingleton() {
// TODO Auto-generated constructor stub
}
public static LaySingleton getinstance(){
return instanle;
}
}