JDBC 單例模式
阿新 • • 發佈:2019-01-03
餓漢模式
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;
}