java - Thread lock after opening new EntityManager -
i have weird error working spring jpa transactions. thread locked around 16 minutes , continues without problem.
here situation:
@transactional(propagation = propagation.requires_new) public class { public string encrypt(string str){ log.debug("encrypting..."); // data base read operations } public string encrypt(string str, string str2){ // read , write database operations. } public string foo(...){ // read , write database operations. } public string bar(...){ // read , write database operations. } } @transactional(propagation = propagation.requires_new) public class b { public string dosomething(...){ log.debug("calling encrypt method..."); string chain1 = this.a.encrypt("whatever"); log.debug("calling encrypt method..."); string chain2 = this.a.encrypt("again"); log.debug("calling encrypt method..."); string chain3 = this.a.encrypt("and again"); ... } }
taking log file see takes 16 minutes log "calling encrypt method" "encripting". so, have activated jta logs , see:
15:09:04.317 debug e.i.n.p.d.tipomensajedaodelegate [45] - obteniendo mensaje para tipo operacion 0104 y protocolo 03 15:09:04.318 debug o.s.orm.jpa.jpatransactionmanager [332] - found thread-bound entitymanager [org.hibernate.ejb.entitymanagerimpl@4e6b01e9] jpa transaction 15:09:04.319 debug o.s.orm.jpa.jpatransactionmanager [471] - participating in existing transaction 15:09:04.320 debug o.s.orm.jpa.jpatransactionmanager [332] - found thread-bound entitymanager [org.hibernate.ejb.entitymanagerimpl@4e6b01e9] jpa transaction 15:09:04.321 debug o.s.orm.jpa.jpatransactionmanager [471] - participating in existing transaction 15:09:04.324 debug e.i.n.c.p.p.b.b [485] - calling encrypt method... 15:09:04.325 debug o.s.orm.jpa.jpatransactionmanager [332] - found thread-bound entitymanager [org.hibernate.ejb.entitymanagerimpl@4e6b01e9] jpa transaction 15:09:04.326 debug o.s.orm.jpa.jpatransactionmanager [416] - suspending current transaction, creating new transaction name [es.indra.nnp.gestorclaves.gestorclavesserviceimpl.cifrar] 15:09:04.326 debug o.s.orm.jpa.jpatransactionmanager [369] - opened new entitymanager [org.hibernate.ejb.entitymanagerimpl@27f2b012] jpa transaction ... 15:24:29.954 debug o.s.orm.jpa.jpatransactionmanager [408] - not exposing jpa transaction [org.hibernate.ejb.entitymanagerimpl@27f2b012] jdbc transaction because jpadialect [org.springframework.orm.jpa.defaultjpadialect@4d832b01] not support jdbc connection retrieval 15:24:29.955 debug e.i.n.g.a [146] - encrypting 15:24:29.956 debug o.s.orm.jpa.jpatransactionmanager [332] - found thread-bound entitymanager [org.hibernate.ejb.entitymanagerimpl@27f2b012] jpa transaction 15:24:29.957 debug o.s.orm.jpa.jpatransactionmanager [471] - participating in existing transaction 15:24:29.958 debug o.s.orm.jpa.jpatransactionmanager [332] - found thread-bound entitymanager [org.hibernate.ejb.entitymanagerimpl@27f2b012] jpa transaction 15:24:29.958 debug o.s.orm.jpa.jpatransactionmanager [471] - participating in existing transaction 15:24:29.962 debug o.s.orm.jpa.jpatransactionmanager [332] - found thread-bound entitymanager [org.hibernate.ejb.entitymanagerimpl@27f2b012] jpa transaction 15:24:29.962 debug o.s.orm.jpa.jpatransactionmanager [471] - participating in existing transaction ...
here, facts:
- error not happen always, when in same point.
- after 16 minutes more or less, thread continues , calls same method few times no problem , finish correctly.
- when happens, around 15 minutes , 30 seconds.
- it happens no concurrency. anyway, when thread locked, if start thread there no problem. second thread processed while first still locked.
- ddbb has being checked looking database locks while lock happening. no database locks found.
- others methods form class called others points of code no problem.
- just happens on production environment. can imagine how difficult changes.
- database connection done via jndi mysql , application run in tomcat.
i know information difficult find out problem is. hope can contribute thoughts me find happening.
for me sounds pretty this question.
using requires_new ensure new transaction, if there existing 1 should suspended.
but since nested transactions not supported jpatransactionmanager:
on jdbc 3.0, transaction manager supports nested transactions via jdbc 3.0 savepoints. abstractplatformtransactionmanager.setnestedtransactionallowed(boolean) "nestedtransactionallowed"} flag defaults "false", though, nested transactions apply jdbc connection, not jpa entitymanager , cached objects. can manually set flag "true" if want use nested transactions jdbc access code participates in jpa transactions (provided jdbc driver supports savepoints). note jpa not support nested transactions! hence, not expect jpa access code semantically participate in nested transaction.
so 2 transactions share same jdbc connection , there might locking involved. transaction timeout set 15 minutes , that's why see hanging around amount of time?
Comments
Post a Comment