[
https://issues.apache.org/jira/browse/OPENJPA-437?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12562686#action_12562686
]
Kevin Sutter commented on OPENJPA-437:
--------------------------------------
Patrick,
Thanks for taking a look at this.
I went through the same type of concerns when I was coming up with the original
patch. But, it was my understanding that the ConcurrentReferenceHashSet still
has an unprotected Iterator. So, later on in this same loadPersistentTypes()
method, the _pcClassNames structure is iterated through. To make this iterator
safe, then I would have to synchronize around this as well. Also, the
_pcClassLoaders should also be made thread-safe since we're updating that
structure in this same method. When I put in all of the necessary safeguards,
it looked like it might be cleaner just by making the method synchronized.
But, if we're hitting a bottleneck by making that method synchronized, then we
probably need to change it. I had not discovered that bottleneck yet...
So, do we need to add the following items to your patch?
o Initialize _pcClassLoaders with a ConcurrentReferenceHashSet.
o Protect the _pcClassNames iterator usage with a synch block
Thanks,
Kevin
> EntityManagerFactory is not thread-safe
> ---------------------------------------
>
> Key: OPENJPA-437
> URL: https://issues.apache.org/jira/browse/OPENJPA-437
> Project: OpenJPA
> Issue Type: Bug
> Components: kernel
> Affects Versions: 1.0.0, 1.0.1, 1.0.2, 1.1.0
> Reporter: Kevin Sutter
> Assignee: Kevin Sutter
> Fix For: 1.0.2, 1.1.0
>
> Attachments: OPENJPA-437-nosync.patch
>
>
> Under certain conditions, we have discovered that the EntityManagerFactory is
> not thread safe when creating EntityManagers. The problem is in the
> loadPersistentTypes method of the AbstractBrokerFactory. There is an
> unprotected data structure (_pcClassNames) that can various problems
> (NullPointerException, IndexOutOfBoundsException, etc) when attempting to add
> new elements to the ArrayList. Other similar datastructures in this part are
> properly synchronized (_pcClassLoaders for example), but somehow we missed
> this one.
> A common scenario where this might be encountered is if your SLSB has an
> injected PersistenceUnit (EntityManagerFactory), but is attempting to create
> the EntityManager during a post-bean creation method (@PostConstruct). In
> this case, the SLSB instances are probably using the same EMF instance (of
> course this would depend on your application server implementation). If you
> have this type of environment, then hitting these SLSB's with multiple
> clients could get you into this situation.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.