看设计模式里面的"Singleton"模式的实现

解决方案 »

  1.   

    public class MyObject{
       private static MyObject instance = null;
       
       public static MyObject getInstance(){
              if (instance == null) instance = new MyObject();
              return instance;
       }   //private, you can't create new instance by yourself
       private MyObject(){
               ....
       }
    }
      

  2.   

    同意hht(影舞者),兄弟:设计模式很重要的说~
      

  3.   

    运行的原理是怎么样的?如多人请求这个instance时,
    系统是采取排队还是随机,还是其它?