openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgras...@apache.org
Subject svn commit: r1338875 - in /openjpa/branches/1.2.x: openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashSet.java
Date Tue, 15 May 2012 20:19:54 GMT
Author: jgrassel
Date: Tue May 15 20:19:53 2012
New Revision: 1338875

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

Modified:
    openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java
    openjpa/branches/1.2.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashSet.java

Modified: openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java?rev=1338875&r1=1338874&r2=1338875&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java
(original)
+++ openjpa/branches/1.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java
Tue May 15 20:19:53 2012
@@ -21,12 +21,12 @@ package org.apache.openjpa.enhance;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
-import java.util.LinkedList;
 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;
 import org.apache.openjpa.util.InvalidStateException;
 
@@ -47,7 +47,9 @@ public class PCRegistry {
         (ReferenceMap.WEAK, 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<RegisterClassListener> _listeners = 
+                    new ConcurrentReferenceHashSet<RegisterClassListener>(ConcurrentReferenceHashSet.WEAK);
 
     /**
      * Register a {@link RegisterClassListener}.
@@ -209,8 +211,11 @@ public class PCRegistry {
             _metas.put(pcClass, meta);
         }
         synchronized (_listeners) {
-            for (Iterator i = _listeners.iterator(); i.hasNext();)
-                ((RegisterClassListener) i.next()).register(pcClass);
+            for (RegisterClassListener r : _listeners) {
+                if (r != null) {
+                    r.register(pcClass);
+                }
+            }
         }
     }
 

Modified: openjpa/branches/1.2.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashSet.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashSet.java?rev=1338875&r1=1338874&r2=1338875&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashSet.java
(original)
+++ openjpa/branches/1.2.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/concurrent/ConcurrentReferenceHashSet.java
Tue May 15 20:19:53 2012
@@ -35,7 +35,7 @@ import org.apache.commons.collections.se
  * @author Abe White
  * @nojavadoc
  */
-public class ConcurrentReferenceHashSet implements Set, Serializable {
+public class ConcurrentReferenceHashSet<E> implements Set<E>, Serializable {
 
     /**
      * Hard reference marker.
@@ -54,7 +54,7 @@ public class ConcurrentReferenceHashSet 
 
     private static final Object DUMMY_VAL = new Object();
 
-    private final Set _set;
+    private final Set<E> _set;
 
     /**
      * Construct a set with the given reference type.
@@ -70,11 +70,11 @@ public class ConcurrentReferenceHashSet 
         }
     }
 
-    public boolean add(Object obj) {
+    public boolean add(E obj) {
         return _set.add(obj);
     }
 
-    public boolean addAll(Collection coll) {
+    public boolean addAll(Collection<? extends E> coll) {
         return _set.addAll(coll);
     }
 
@@ -86,7 +86,7 @@ public class ConcurrentReferenceHashSet 
         return _set.contains(obj);
     }
 
-    public boolean containsAll(Collection coll) {
+    public boolean containsAll(Collection<?> coll) {
         return _set.containsAll(coll);
     }
 
@@ -94,7 +94,7 @@ public class ConcurrentReferenceHashSet 
         return _set.isEmpty();
     }
 
-    public Iterator iterator() {
+    public Iterator<E> iterator() {
         return _set.iterator();
     }
 
@@ -102,11 +102,11 @@ public class ConcurrentReferenceHashSet 
         return _set.remove(obj);
     }
 
-    public boolean removeAll(Collection coll) {
+    public boolean removeAll(Collection<?> coll) {
         return _set.removeAll(coll);
     }
 
-    public boolean retainAll(Collection coll) {
+    public boolean retainAll(Collection<?> coll) {
         return _set.retainAll(coll);
     }
 
@@ -118,7 +118,7 @@ public class ConcurrentReferenceHashSet 
         return _set.toArray();
     }
 
-    public Object[] toArray(Object[] arr) {
+    public <T> T[] toArray(T[] arr) {
         return _set.toArray(arr);
     }
 



Mime
View raw message