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.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/1.0.x@612846 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Kevin W. Sutter 2008-01-17 15:35:45 +00:00
parent b013b6fd4a
commit 8ef7997457
1 changed files with 8 additions and 3 deletions

View File

@ -133,6 +133,7 @@ public abstract class AbstractBrokerFactory
*/ */
protected AbstractBrokerFactory(OpenJPAConfiguration config) { protected AbstractBrokerFactory(OpenJPAConfiguration config) {
_conf = config; _conf = config;
_pcClassLoaders = new ReferenceHashSet(ReferenceHashSet.WEAK);
} }
/** /**
@ -231,8 +232,13 @@ public abstract class AbstractBrokerFactory
/** /**
* Load the configured persistent classes list. Performed automatically * Load the configured persistent classes list. Performed automatically
* whenever a broker is created. * 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? // no listed persistent types?
if (_pcClassNames != null && _pcClassNames.isEmpty()) if (_pcClassNames != null && _pcClassNames.isEmpty())
return; return;
@ -245,7 +251,7 @@ public abstract class AbstractBrokerFactory
Collection clss = _conf.getMetaDataRepositoryInstance(). Collection clss = _conf.getMetaDataRepositoryInstance().
loadPersistentTypes(false, loader); loadPersistentTypes(false, loader);
if (clss.isEmpty()) if (clss.isEmpty())
_pcClassNames = Collections.EMPTY_SET; _pcClassNames = Collections.EMPTY_LIST;
else { else {
_pcClassNames = new ArrayList(clss.size()); _pcClassNames = new ArrayList(clss.size());
for (Iterator itr = clss.iterator(); itr.hasNext();) { for (Iterator itr = clss.iterator(); itr.hasNext();) {
@ -254,7 +260,6 @@ public abstract class AbstractBrokerFactory
if (needsSub(cls)) if (needsSub(cls))
toRedefine.add(cls); toRedefine.add(cls);
} }
_pcClassLoaders = new ReferenceHashSet(ReferenceHashSet.WEAK);
_pcClassLoaders.add(loader); _pcClassLoaders.add(loader);
} }
} else { } else {