openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwsut...@apache.org
Subject svn commit: r612846 - in /openjpa: branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
Date Thu, 17 Jan 2008 15:35:59 GMT
Author: kwsutter
Date: Thu Jan 17 07:35:45 2008
New Revision: 612846

URL: http://svn.apache.org/viewvc?rev=612846&view=rev
Log:
OPENJPA-437.  Changed AbstractBrokerFactory.loadPersistentTypes to be synchronized to get
around the multi-threading issue during broker creation.

Also, migrated the change for OPENJPA-449 from trunk to the 1.0.x branch.

Modified:
    openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java

Modified: openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java?rev=612846&r1=612845&r2=612846&view=diff
==============================================================================
--- openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
(original)
+++ openjpa/branches/1.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
Thu Jan 17 07:35:45 2008
@@ -133,6 +133,7 @@
      */
     protected AbstractBrokerFactory(OpenJPAConfiguration config) {
         _conf = config;
+        _pcClassLoaders = new ReferenceHashSet(ReferenceHashSet.WEAK);
     }
 
     /**
@@ -231,8 +232,13 @@
     /**
      * Load the configured persistent classes list. Performed automatically
      * whenever a broker is created.
+     * 
+     * This method is synchronized due to the possible creation of new brokers
+     * (entity managers) by multiple threads (clients).  The two data structures
+     * used by this method (_pcClassNames and _pcClassLoaders) are not thread
+     * safe and this was an easy, efficient solution (OPENJPA-437).
      */
-    private void loadPersistentTypes(ClassLoader envLoader) {
+    private synchronized void loadPersistentTypes(ClassLoader envLoader) {
         // no listed persistent types?
         if (_pcClassNames != null && _pcClassNames.isEmpty())
             return;
@@ -245,7 +251,7 @@
             Collection clss = _conf.getMetaDataRepositoryInstance().
                 loadPersistentTypes(false, loader);
             if (clss.isEmpty())
-                _pcClassNames = Collections.EMPTY_SET;
+                _pcClassNames = Collections.EMPTY_LIST;
             else {
                 _pcClassNames = new ArrayList(clss.size());
                 for (Iterator itr = clss.iterator(); itr.hasNext();) {
@@ -254,7 +260,6 @@
                     if (needsSub(cls))
                         toRedefine.add(cls);
                 }
-                _pcClassLoaders = new ReferenceHashSet(ReferenceHashSet.WEAK);
                 _pcClassLoaders.add(loader);
             }
         } else {

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java?rev=612846&r1=612845&r2=612846&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
Thu Jan 17 07:35:45 2008
@@ -256,8 +256,13 @@
     /**
      * Load the configured persistent classes list. Performed automatically
      * whenever a broker is created.
+     * 
+     * This method is synchronized due to the possible creation of new brokers
+     * (entity managers) by multiple threads (clients).  The two data structures
+     * used by this method (_pcClassNames and _pcClassLoaders) are not thread
+     * safe and this was an easy, efficient solution (OPENJPA-437).
      */
-    private void loadPersistentTypes(ClassLoader envLoader) {
+    private synchronized void loadPersistentTypes(ClassLoader envLoader) {
         // no listed persistent types?
         if (_pcClassNames != null && _pcClassNames.isEmpty())
             return;
@@ -270,7 +275,7 @@
             Collection clss = _conf.getMetaDataRepositoryInstance().
                 loadPersistentTypes(false, loader);
             if (clss.isEmpty())
-                _pcClassNames = Collections.EMPTY_SET;
+                _pcClassNames = Collections.EMPTY_LIST;
             else {
                 _pcClassNames = new ArrayList(clss.size());
                 for (Iterator itr = clss.iterator(); itr.hasNext();) {



Mime
View raw message