openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgras...@apache.org
Subject svn commit: r1338919 - /openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java
Date Tue, 15 May 2012 22:19:36 GMT
Author: jgrassel
Date: Tue May 15 22:19:35 2012
New Revision: 1338919

URL: http://svn.apache.org/viewvc?rev=1338919&view=rev
Log:
OPENJPA-2042: Diagnostics for Application Managed EntityManagerFactory leaks.

Modified:
    openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java

Modified: openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java?rev=1338919&r1=1338918&r2=1338919&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java
(original)
+++ openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java
Tue May 15 22:19:35 2012
@@ -27,6 +27,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;
 
 /**
@@ -45,7 +46,9 @@ public class PCRegistry {
             ReferenceMap.HARD);
 
     // register class listeners
-    private static final Collection<RegisterClassListener> _listeners = new LinkedHashSet<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}.
@@ -202,8 +205,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);
+                }                
+            }
         }
     }
 



Mime
View raw message