/*
单例设计模式中的同步代码块
*/
//饿汉式
/*
class Single
{
public static final Single s= new Single;
private Single() {}
public static Single getInstance()
{
retrun s;
}
}
*/
//懒汉式
class Single
{
public static Single s=null;
private Single(){}
public static Single getInstance()
{
if(s==null)//用双重判断减少了锁的判断次数
{
synchronized (Single.class)
if(s==null)
s= new Single();
return s;
}
}
}