OPENJPA-2042: Diagnostics for Application Managed EntityManagerFactory leaks.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.0.x@1338900 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jody Grassel 2012-05-15 21:20:13 +00:00
parent 8052dfd4ee
commit 7b36aa53c5
1 changed files with 9 additions and 3 deletions

View File

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