您的位置:首页 > 其它

多线程-单例设计模式懒汉 饿汉

2016-06-01 23:16 387 查看
饿汉
class Single{
private static final Single s = new  Single();
private Single();
private static Single getInstance(){

return a;
}

}
懒汉
class Single
{
private static Single s= null;
private Single(){}
public static Single getInstance){
if(s == null){
synchronized (Single.class){
if(s == null){
s = new Single();
}
}
}
return s;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: