java lock wait_java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction

在开发测试过程中发现出了这个问题:

RECHARGE:业务,数据: {"platformUserNo":"RPD_1512632756191","amount":6000,"rechargeWay":"SWIFT","bankcode":"ICBK","payCompany":"LANMAO","payMobile":"13428284220","transactionTime":"20171228154506","rechargeStatus":"SUCCESS","commission":0,"requestNo":"20171228154433","code":"0","status":"SUCCESS"} 。回调处理异常--》

org.springframework.dao.CannotAcquireLockException: Hibernate operation: Could not execute JDBC batch update; SQL [update recharge set orderNum=?, pIpsBillNo=?, pay_company=?, reAccount=?, rechargeAmount=?, status=?, time=? where id=?]; Lock wait timeout exceeded; try restarting transaction; nested exception is java.sql.BatchUpdateException: Lock wait timeout exceeded; try restarting transaction

at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:265)

Caused by: java.sql.BatchUpdateException: Lock wait timeout exceeded; try restarting transaction

at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2054)

at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1467)

at com.p6spy.engine.wrapper.StatementWrapper.executeBatch(StatementWrapper.java:98)

at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)

at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)

at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)

... 134 more

Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2794)

at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)

at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)

at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2006)

其实也就 是 业务执行失败了, 事务 不能提交。 可以看到是 update 出现问题了。 百度了一下 , 都是 数据库 死锁了, 乐观锁什么的

开始是 以为程序出现 死循环了, 可是看了一下其实并不是。 然后 测试的时候,发现有时候 可以,有时候又不行。 后来通过 打印日志 才知道原因。 原来是 重复执行的问题。 确实 在业务处理里面使用到了 乐观锁。程序同步锁。等,业务是有点复杂。 也就是前端 form 表单 重复提交了,甚至提交了多次。。。 所以 因为 一个事务里面 涉及到了多张表,而 多个线程一起执行这个方法的时候, 就会出现 数据库死锁的问题。 每个线程 锁住了 一张表某行,而 想要 获取 其他线程锁住的表某行数据的 锁进行更新 , 所以就出现 互相等待。。。直到 事务 超时。。。

这种情况,特别是 和 第三方平台进行对接业务的时候,比如直连请求,同步回调啊,异步回调啊,,, 都是有可能重复 接收的。 就算 发送 也是有可能重复发送的。 鉴别 是否重复响应,请求还是 有一定的必要性的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值