Package Create type _ single case mode _ registration type;
Import Java.util.HashMap;
Import Java.util.Map; /** * Registered Singleton actually maintains an instance of a set of singleton classes, store these instances in a map (register) *, return directly from the factory for a single instance that has already been registered, and register for unregistered, and then return * @author PP */public Class Regsingleton {/** * register, used to hold all registered instances/private static map<string, regsingleton> Map = new H
Ashmap<string, regsingleton> ();
Add an instance to the register when the class is loaded static{Regsingleton singleton = new Regsingleton (); Map.put (Singleton.getclass (). GetName (), singleton)//Using reflection}/** * Protected default construction Method */protected Regsingle ton () {}/** * Static Factory method, returning the only instance of the specified Registration object * For a registered direct fetch return, register before it is registered, and then take out the return * * * */Publi
C Static Regsingleton getinstance (String name) {if (name==null) {name= "Regsingleton"; } if (Map.get (name) ==null) {try {map.put (name), (Regsingleton) class.forname (name). Newi
Nstance ()); catch (Exception e) {e.printsTacktrace ();
} return Map.get (name);
/** * A schematic business method/public String about () {return "hello,i am Regsingleton";
}
}