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;
    }

你可能感兴趣的:(笔记)