记录一下:
原因:spring事务提交时导致数据库事务得不到释放,产生死锁问题,紧接着抛出操作超时异常:MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
有可能是因为spring的事务嵌套引起的问题,总之先解决眼前的问题,把mysql中产生死锁的事务进程干掉,所以记录一下sql
相关sql记录:
-- 查看数据库当前的进程
show processlist;
-- 当前运行的所有事务
SELECT * FROM information_schema.INNODB_LOCKs;
-- 当前出现的锁
SELECT * FROM information_schema.INNODB_LOCK_waits;
-- 锁等待的对应关系
SELECT * FROM information_schema.INNODB_TRX;
-- 查询产生锁的具体sql
select
a.trx_id 事务id ,
a.trx_mysql_thread_id 事务线程id,
a.trx_query 事务sql
from
INFORMATION_SCHEMA.INNODB_LOCKS b,
INFORMATION_SCHEMA.innodb_trx a
where
b.lock_trx_id=a.trx_id;
-- !!!
select concat('KILL ',a.trx_mysql_thread_id ,';')
from INFORMATION_SCHEMA.INNODB_LOCKS b,INFORMATION_SCHEMA.innodb_trx a
where b.lock_trx_id=a.trx_id;
-- 杀掉死锁进程
kill {thread_id};
解决:
在事务回滚注解中添加参数:propagation = Propagation.REQUIRES_NEW(默认为:Propagation.REQUIRED)
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
ResponseData updateBath(List<Entity> entity) throws ParseException;