Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Design Pattern & UML  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 单子模式的双重检测
andy_wang_5





发贴: 101
积分: 14
于 2007-09-25 11:28 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
public class LazySingleton {
public static LazySingleton m_instance = null;
/**
*私有的默认构造函数,保证外界没办法直接实列化。
*/
private LazySingleton() {}
/**
*静态工厂方法,返回此类的惟一实列
*/
public static LazySingleton getInstance() {
if (m_instance == null) {
//more than one threads might be here!!!
synchronized (LazySingleton.class) {
if (m_instance == null) {
m_instance = new LazySingleton();
}
}
}
return m_instance;
}
}

为什么如上的双重检测不适用于java,而使用与C++ ?请高手指点。



鹰行折翼 再盼凌云
作者 Re:单子模式的双重检测 [Re:andy_wang_5]
JiafanZhou



版主


发贴: 736
积分: 61
于 2007-09-25 17:11 user profilesend a private message to usersend email to JiafanZhousearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
C++ uses a different thread scheduling mechanism which is different from the one in Java in essence.


When I was a kid I used to pray every night for a new bike. Then I realized that The Lord doesn't work that way, so I stole one and asked him to forgive me.

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2018 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号
客服电话 0592-8750026    客服信箱 714923@qq.com    客服QQ 714923