java - Which kind of Singleton is this? -


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 saw code somewhere singleton pattern not used per book definition gof. singleton storing map of own instances.

what kind of singleton can called? or valid use of singleton?

it's not singleton. it's called multiton pattern.

rather have single instance per application, multiton pattern instead ensures single instance per key.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -