1. 程式人生 > >JDBC 單例模式

JDBC 單例模式

餓漢模式

public static ConfigManager getInstance(){
        if (configManager==null) {
            configManager=new ConfigManager();
        }
        return configManager;
    }

懶漢模式

public static synchronized ConfigManager getInstance(){

            if (configManager==null) {
                configManager=new
ConfigManager(); } return configManager; }

雙重鎖定

public static synchronized ConfigManager getInstance(){
        if(configManager==null){
            synchronized (ConfigManager.class){
                if(configManager==null){
                    configManager=new ConfigManager();
                }
            }
        }
        return
configManager; }