• 单例模式


    
    
    public class DataBaseContext {
    
        private static DataHelper dataHelper;
        private static Object     INSTANCE_LOCK = new Object();
    
        public static DataHelper getInstance(Context context) {
        
            synchronized (INSTANCE_LOCK) {
            
               if (dataHelper == null) {
                  dataHelper = new DataHelper(context);
                }
            
               return dataHelper;
            }
        }
    }
    
    
    /*  懒汉式单例 */
    public class Singleton {
        
        private static Singleton uniqueInstance = null;
        
        private Singleton() {}
        
        public static synchronized Singleton getInstance ( ) {
        
           if ( uniqueInstance == null ) {
               uniqueInstance = new Singleton();
           }
        
           return uniqueInstance;
        }
    }
    
    
    /*  饿汉式单例 */
    public class Singleton {
        
        private static Singleton uniqueInstance =  new Singleton();
        
        private Singleton() {}
       
        public static  Singleton getInstance ( ) {
            return uniqueInstance;
        }
    }
     
  • 相关阅读:
    What Kind of Friends Are You? ZOJ 3960
    博弈随笔(未完待续)
    Mergeable Stack ZOJ
    LIS ZOJ
    差分约束 HDU
    How far away ? HDU
    wya费用流
    不知道说些什么
    ext大法好啊
    bzoj2348
  • 原文地址:https://www.cnblogs.com/surong/p/2482243.html
Copyright © 2020-2023  润新知