@@ -0,0 +1,804 @@
+package com.yxy.chukonu.java.dp.singleton;%0A%0Aimport java.util.HashMap;%0A%0Apublic class RegistrySingleton %7B%0A%09private static HashMap registry = new HashMap();%0A%0A%09static %7B%0A%09%09RegistrySingleton rs = new RegistrySingleton();%0A%09%09registry.put(rs.getClass().getName(), rs);%0A%09%7D%0A%0A%09// protected constructor granted class inheritance features%0A%09protected RegistrySingleton() %7B%0A%09%7D%0A%0A%09public static RegistrySingleton getInstance(String name) %7B%0A%09%09if (name == null) %7B%0A%09%09%09name = %22RegistrySingleton%22;%0A%09%09%7D%0A%0A%09%09if(registry.get(name) == null) %7B //double check%0A%09%09%09synchronized(registry) %7B%0A%09%09%09%09if(registry.get(name) == null) %7B%0A%09%09%09%09%09try %7B%0A%09%09%09%09%09%09registry.put(name, Class.forName(name).newInstance());%0A%09%09%09%09%09%7D catch (Exception ex) %7B%0A%09%09%09%09%09%09ex.printStackTrace();%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09return (RegistrySingleton) registry.get(name);%0A%09%7D%0A%7D%0A

add registry singleton example