public class ConnectionManager {
private static Map <String, ConnectionManager> managerInstances = new HashMap<String, ConnectionManager>();
private String dsKey;
private ConnectionManager(String dsKey){
this.dsKey = dsKey;
}
public static ConnectionManager getInstance(String dsKey){
ConnectionManager managerInstance = managerInstances.get(dsKey);
if (managerInstance == null) {
synchronized (ConnectionManager.class) {
managerInstance = managerInstances.get(dsKey);
if (managerInstance == null) {
managerInstance = new ConnectionManager(dsKey);
managerInstances.put(dsKey, managerInstance);
}
}
}
return managerInstance;
}
}
I recently saw this code somewhere where the Singleton pattern was not used as per book definition from GoF. Singleton is storing a Map
of its own instances.
What kind of singleton can this be called? Or is this a valid use of Singleton?