You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Scott Parkerson (JIRA)" <ji...@apache.org> on 2012/07/25 21:02:35 UTC

[jira] [Comment Edited] (OPENJPA-1716) Deadlock with openjpa.Multithreaded=true

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

Scott Parkerson edited comment on OPENJPA-1716 at 7/25/12 7:01 PM:
-------------------------------------------------------------------

I, too, have run into this problem when trying to use a container-managed JPA persistence context in Apache Servicemix (Fusesource Fuse ESB). The problem occurs when using Apache Aries Blueprint JPA / JTA which creates the EntityManagerFactory for the persistence unit at bundle start, and then injects an EntityManager into each DAO that I create that is part of the persistence unit. Those DAOs are exposed as OSGi services to business services, which are then called by webservices, Camel routes, etc.

Everything is fine until two or more threads hit an EntityManager; at that point, we get the warning to try openjpa.Multithreaded=true. Adding that to my Persistence Context configuration causes the aforementioned deadlock (same trace and everything).

If changing the applications is required to work around this without a patch, then can you recommend a way to do this using the container to manage persistence?

(FWIW, this is still happening as of 2.2.0; might want to update the affects version.)
                
      was (Author: snortasprocket):
    I, too, have run into this problem when trying to use a container-managed JPA persistence context in Apache Servicemix (Fusesource Fuse ESB). The problem occurs when using Apache Aries Blueprint JPA / JTA which creates the EntityManagerFactory for the persistence unit at bundle start, and then injects an EntityManager into each DAO that I create that is part of the persistence unit. Those DAOs are exposed as OSGi services to business services, which are then called by webservices, Camel routes, etc.

Everything is fine until two or more threads hit an EntityManager; at that point, we get the warning to try openjpa.Multithreaded=true. Adding that to my Persistence Context configuration causes the aforementioned deadlock (same trace and everything).

If changing the applications is required to work around this without a patch, then can you recommend a way to do this using the container to manage persistence?
                  
> Deadlock with openjpa.Multithreaded=true
> ----------------------------------------
>
>                 Key: OPENJPA-1716
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1716
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 2.0.0-M1, 2.0.0-M2, 2.0.0-M3, 2.0.0-beta, 2.0.0-beta2, 2.0.0-beta3, 2.0.0
>            Reporter: Stefan Wokusch
>            Assignee: Rick Curtis
>         Attachments: OPENJPA-1716.PATCH
>
>
> There is a Deadlock by using Multithreaded=true and work with some Threads on the same Entitymanager.
> After many hours of debugging, i found a solution for that Deadlock: The Problem could be solved by adding another lock into the lock Method of the StateManagerImpl:
> StateManagerImpl ~line3308
>     /**
>      * Lock the state manager if the multithreaded option is set.
>      */
>     protected void lock() {
>         if (_instanceLock != null){
>         	_broker.lock();//<- This is the new Part to fix the Deadlock
>         	_instanceLock.lock();
>         }
>     }
> Worked for me without Problems for a long time.
> Some other Configurations:
> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
> 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
> 	<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
> 		<mapping-file>orm.xml</mapping-file>
> 		
> 		<class>...</class>
> 		<class>...</class>
> 		
> 		<properties>
> 			<property name="openjpa.OrphanedKeyAction" value="log(Channel=Orphans, Level=TRACE)" />
> 			<property name="openjpa.ConnectionFactoryProperties" value="PrettyPrint=true, PrettyPrintLineLength=80" />
> 			<property name="openjpa.Multithreaded" value="true" />
> 			<property name="openjpa.InverseManager" value="true" />
> 			<property name="openjpa.LockManager" value="none" />
> 			<property name="openjpa.WriteLockLevel" value="none" />
> 			<property name="openjpa.Compatibility" value="
> 					QuotedNumbersInQueries=true, 
> 					CopyOnDetach=true,
> 					cascadeWithDetach=true,
> 					superclassDiscriminatorStrategyByDefault=false
> 			" />
> 			<property name="openjpa.DetachState" value="fetch-groups" />
> 			<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema" />
> 			<!-- Default DataSource -->
> 			<property name="openjpa.ConnectionURL" value="jdbc:h2:db/test" />
> 			<property name="openjpa.ConnectionDriverName" value="org.h2.Driver" />
> 		</properties>
> 	</persistence-unit>
> </persistence>

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira