[ 
https://issues.apache.org/jira/browse/OPENJPA-324?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12521868
 ] 

Chris Ward commented on OPENJPA-324:
------------------------------------

I have tried listing and not list the types in the persistence unit with the 
same result.  If you access the EM before doing any real work then it is not a 
problem, because you have a single thead that is triggering the load of data 
into the MetaDataRepository.  I am using OpenJPA within a web service and I can 
potentialy have several threads accessing an EMF to acquire an EM per thread at 
the same time and performing real work.  Since the metadata is lazy loaded into 
the MetaDataRepository you can have multiple threads triggering the load at the 
same time.  After looking at the code I was able to exaggerate the problem by 
adding a sleep call within the MetaDataRepository to consistently reproduce the 
problem.  I left that line commented out in the attached java file.  If you put 
the line in the same spot in the old code you should be able to reproduce the 
problem on a multi core machine.

The first thread to try to load the meta data always succeeds, and all other 
threads concruently trying to load the meta data always fail.  Once the meta 
data has been loaded, all new requests coming in succeed.  It is only a problem 
durring the load.

> The MetaDataRepository class is not thread safe.  Initialization under heavy 
> load on a multi CPU/Core systems throws exceptions.
> --------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-324
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-324
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 0.9.6, 0.9.7
>         Environment: I have reproduced the problem in Windows and in Solaris. 
>  It only affects multi core/CPU systems.  I haven't reproduced the problem on 
> single core systems.
> I am using Spring 2.0.2 and OpenJPA 0.9.6 with an Oracle 10g database.
>            Reporter: Chris Ward
>         Attachments: MetaDataRepository.java
>
>
> OpenJPA's MetaDataRepository fails to load metadata for classess when 
> multiple threads use the same EntityManagerFactory class to resolve the 
> metadata.  The MetaDataRepository implementation is not thread safe.The 
> problem only occurrs on multi core or multi processor machines that can 
> concurrently try to initialize meta data for classes.
> To reproduce the problem I have inserted a sleep statement within the code to 
> help reproduce the problem consistently.  I have commented out the sleep 
> statement in my deployed version of the class.
> This bug is sort of related to issue 250.  I have cleaned up all of the 
> synchronization in the class.  There should be less contention, however it 
> could still be better if a ReentrantReadWriteLock was used.  I noticed that 
> someone had posted a new MetaDataRepository with a ReentrantReadWriteLock, 
> but too seems to have the same issues.

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