diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java index d64fc8055..8493ded74 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java @@ -26,6 +26,7 @@ import java.util.Map; import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.ReferenceMap; import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap; +import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashSet; import org.apache.openjpa.util.UserException; /** @@ -44,7 +45,9 @@ public class PCRegistry { ReferenceMap.HARD); // register class listeners - private static final Collection _listeners = new LinkedList(); + // Weak reference prevents OutOfMemeoryError as described in OPENJPA-2042 + private static final Collection _listeners = + new ConcurrentReferenceHashSet(ConcurrentReferenceHashSet.WEAK); /** * Register a {@link RegisterClassListener}. @@ -201,8 +204,11 @@ public class PCRegistry { _metas.put(pcClass, meta); } synchronized (_listeners) { - for (RegisterClassListener r : _listeners) - r.register(pcClass); + for (RegisterClassListener r : _listeners) { + if (r != null) { + r.register(pcClass); + } + } } }