Propagation.REQUIRES_NEW导致LockWaitTimeOutException [英] Propagation.REQUIRES_NEW causing LockWaitTimeOutException
本文介绍了Propagation.REQUIRES_NEW导致LockWaitTimeOutException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有两个功能A和B是用事务注释定义的.
There are two functions A and B which are defined with Transactional annotation.
我从A打电话给B.
@Transactional(value=Constants.READ_WRITE_REQUEST)
public int A(....){
B();
}
@Transactional(propagation=Propagation.REQUIRES_NEW,value=Constants.READ_WRITE_REQUEST)
public int B(....){
C();
}
@Transactional(value=Constants.READ_WRITE_REQUEST)
public int C(....){
...
}
它导致了
Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
我从函数B中删除了Propagation.REQUIRES_NEW,问题得到解决.
I removed the Propagation.REQUIRES_NEW from the function B and problem got resolved.
是因为旧事务持有该锁而创建了新事务吗? 有什么想法吗?
Is it because old transaction was holding the lock and new one was created? Any thoughts on this?
推荐答案
看起来像是一种死锁,有两个事务,外部事务(来自A
)和内部事务(来自B
)都有一个锁/尝试锁定相同的资源.
Looks like some kind of dead lock, two transactions, the outer (from A
) and the inner (from B
) have a lock/try to lock the same resource.
这篇关于Propagation.REQUIRES_NEW导致LockWaitTimeOutException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文