您的位置:首页 > 职场人生

黑马程序员-多线程-11天-3

2013-04-07 22:32 176 查看
/*
单例设计模式。

*/
//饿汉式。
/*
class Single
{
private static final Single s = new Single();
private Single(){}
public static Single getInstance()
{
return s;
}
}
*/

//懒汉式

class Single
{
private static Single s = null;
private Single(){}

public static  Single getInstance()
{
if(s==null)
{
synchronized(Single.class)
{
if(s==null)
//--->A;
s = new Single();
}
}
return s;
}
}

class SingleDemo
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: