Chinaunix

标题: 关于Single Pattern [打印本页]

作者: PassionUranus    时间: 2007-08-28 00:06
标题: 关于Single Pattern
在我们写单例模式的代码时,一般都这样来:
public class Singletnon   
{   
    private static Singletnon instance;   
   
    public Singletnon()   
    {   
   
    }   
   
    public static Singletnon getInstance()   
    {      
         if (instance == null)   
         {   
                      //
                    instance = new Singletnon();   
                    

         }      
        return instance;   
    }   
};   

那现在我写多线程的代码,怎么来编这种模式的代码,各位看看,代码就写Pthread的代码吧。
作者: jeffwang8001    时间: 2007-08-28 08:56
啥意思?
貌似Singleton的构造函数应该是protected和private的吧
作者: web_surf    时间: 2007-08-28 09:11
原帖由 PassionUranus 于 2007-8-28 00:06 发表
在我们写单例模式的代码时,一般都这样来:
public class Singletnon   
{   
    private static Singletnon instance;   
   
    public Singletnon()   
    {   
   
    }   
   
    pu ...



加锁-解锁
作者: xiaomiao    时间: 2007-08-28 09:27
提示: 作者被禁止或删除 内容自动屏蔽
作者: dzbjet    时间: 2007-08-28 09:35
参考ice singleton or ace singleton




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2