MySQL获取锁失败求解-Lock wait timeout exceeded; try restarting transaction
今天程序遇到mysql执行update语句时获取锁超时的问题,现象是update某条记录时报如下错误,而同张表中的其他记录都可以正常update,而且是必现,根据错误信息,猜测问题可能是某次执行update操作时因为某些原因导致改事务(Spring管理的事务)未commit,也未rollback,所以导致该记录行锁一直未释放。
现在我还搞不清楚几个问题,求各位大神指点:
1、我现在如何查看当前数据库中加了哪些行锁,如何手动释放这些锁?
2、为何autocommit = on 的时候会出现这种现象?
3、有什么方法可以避免出现这种行锁未释放的情况?
错误堆栈信息如下:
2015-12-23 17:49:19:ERROR HSFBizProcessor-8-thread-40 com.comm.spring.aop.LogInterceptor - Caused by: org.springframework.dao.CannotAcquireLockException:
### Error updating database. Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
### The error may involve com.biz.po.person.TPersonMapper.updateByPrimaryKeySelective-Inline
### The error occurred while setting parameters
### SQL: update t_person SET gender = ?, location_id = ?, birthdate = ?, name = ?, mobile = ?, id_number = ? where id = ?
### Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
; SQL []; Lock wait timeout exceeded; try restarting transaction; nested exception is java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:261)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
at com.sun.proxy.$Proxy40.update(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:254)
at com.comm.dao.mybatis.impl.DaoHelperImpl.update(DaoHelperImpl.java:309)
at com.biz.service.remotevideo.impl.RemotePatientOrderServiceImpl.updateRemotePatientInfo(RemotePatientOrderServiceImpl.java:282)
at sun.reflect.GeneratedMethodAccessor358.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at com.comm.spring.aop.LogInterceptor.invoke(LogInterceptor.java:55)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at com.comm.spring.aop.LogInterceptor.invoke(LogInterceptor.java:55)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at com.comm.spring.aop.ServiceInterceptor.invoke(ServiceInterceptor.java:51)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at com.comm.spring.aop.ServiceInterceptor.invoke(ServiceInterceptor.java:51)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy81.updateRemotePatientInfo(Unknown Source)
at com.biz.service.remotevideo.impl.RemoteVideoOrderServiceImpl.saveVideoOrder(RemoteVideoOrderServiceImpl.java:166)
at sun.reflect.GeneratedMethodAccessor332.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)