diff --git a/src/org/redkale/util/ResourceFactory.java b/src/org/redkale/util/ResourceFactory.java index a97f63e58..a081c2516 100644 --- a/src/org/redkale/util/ResourceFactory.java +++ b/src/org/redkale/util/ResourceFactory.java @@ -177,19 +177,21 @@ public final class ResourceFactory { checkName(name); ConcurrentHashMap map = this.store.get(clazz); if (map == null) { - ConcurrentHashMap sub = new ConcurrentHashMap(); - sub.put(name, new ResourceEntry(rs)); - store.put(clazz, sub); - return null; - } else { - ResourceEntry re = map.get(name); - if (re == null) { - map.put(name, new ResourceEntry(rs)); - } else { - map.put(name, new ResourceEntry(rs, name, re.elements, autoSync)); + synchronized (clazz) { + map = this.store.get(clazz); + if (map == null) { + map = new ConcurrentHashMap(); + store.put(clazz, map); + } } - return re == null ? null : (A) re.value; } + ResourceEntry re = map.get(name); + if (re == null) { + map.put(name, new ResourceEntry(rs)); + } else { + map.put(name, new ResourceEntry(rs, name, re.elements, autoSync)); + } + return re == null ? null : (A) re.value; } public A find(Class clazz) {