提交 95742236 编写于 作者: W wangzhen

单例工厂模式修改

上级 5c76b5ca
......@@ -11,14 +11,14 @@ import java.util.Map;
* @createTime 2020年06月03日 15:04:00
*/
public final class SingletonFactory {
private static final Map<String, Object> OBJECT_MAP = new HashMap<>();
private static volatile Map<String, Object> OBJECT_MAP = new HashMap<>();
private SingletonFactory() {
}
public static <T> T getInstance(Class<T> c) {
String key = c.toString();
Object instance = null;
Object instance = OBJECT_MAP.get(key);
if (instance == null) {
synchronized (SingletonFactory.class) {
instance = OBJECT_MAP.get(key);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册