//懒汉式,就是创建一个
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;
}
}
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;
}
}