[ 
https://issues.apache.org/jira/browse/OPENJPA-437?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12559564#action_12559564
 ] 

Kevin Sutter commented on OPENJPA-437:
--------------------------------------

Looking at just synchronizing the AbstractBrokerFactory.loadPersistentTypes 
method to resolve this problem.  As I continued to look at this problem, both 
_pcClassNames and _pcClassLoaders are not synchronized.  Patrick's fix for 
OPENJPA-449 to move the creation of the _pcClassLoaders structure to the 
constructor closed the window for the scenario described in OPENJPA-449, but 
it's still not protected from multiple client/thread access.  (Note, my 
previous comments in the Description about _pcClassLoaders being protected were 
not accurate.)

I could change both of these Collections to be synchronized, but the code was 
getting a bit ugly due to the still required synchronization for the iterators. 
 Since these two Collections are only modified in this method, an easy solution 
would be to make the method Synchronized.  Since this method is only used when 
creating new brokers, this shouldn't affect the through put.

Also, the logic for this method is based on the return value of the 
loadPersistentTypes on the MetaDataRepository instance.  This method is also 
synchronized, so we'd be following suit.

Any concerns about going the route of synchronizing the 
AbstractBrokerFactory.loadPersistentTypes method?

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
>
>
> 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.

Reply via email to