这是哪种单身人士?

Nar*_*hai 0 java singleton design-patterns

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

我最近在GoF的书籍定义中没有使用Singleton模式的地方看到了这段代码.Singleton正在存储一个Map自己的实例.

这可以称为什么样的单身人士?或者这是Singleton的有效使用?

ken*_*ytm 9

这不是一个单身人士.它被称为多重模式.

而不是每个应用程序只有一个实例,而是确保每个键的单个实例.