Spring之—— java.sql.SQLException: Lock wait timeout exceeded | CannotAcquireLockException 的解决

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/78615736

一、错误信息

错误日志如下:

2017-11-23 15:20:31 XmlBeanDefinitionReader [INFO] Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2017-11-23 15:20:31 SQLErrorCodesFactory [INFO] SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
2017-11-23 15:20:31 ExceptionUtil [ERROR] SqlMapClient OrderItem; SQL [];   
--- The error occurred in com/defonds/syncpath/dao/OrderItem.xml.  
--- The error occurred while applying a parameter map.  
--- Check the OrderItem.updateShareStatus-InlineParameterMap.  
--- Check the statement (update failed).  
--- Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in com/defonds/syncpath/dao/OrderItem.xml.  
--- The error occurred while applying a parameter map.  
--- Check the OrderItem.updateShareStatus-InlineParameterMap.  
--- Check the statement (update failed).  
--- Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
org.springframework.dao.CannotAcquireLockException: SqlMapClient OrderItem; SQL [];   
--- The error occurred in com/defonds/syncpath/dao/OrderItem.xml.  
--- The error occurred while applying a parameter map.  
--- Check the OrderItem.updateShareStatus-InlineParameterMap.  
--- Check the statement (update failed).  
--- Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in com/defonds/syncpath/dao/OrderItem.xml.  
--- The error occurred while applying a parameter map.  
--- Check the OrderItem.updateShareStatus-InlineParameterMap.  
--- Check the statement (update failed).  
--- Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
  at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:244)
  at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
  at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:212)
  at com.defonds.frameworkcommons.dao.BaseDaoImpl.execute(BaseDaoImpl.java:31)
  at com.defonds.frameworkcommons.dao.BaseDaoImpl.update(BaseDaoImpl.java:97)
  at com.defonds.syncpath.service.OrderItem.impl.OrderItemServiceImpl.revokeSharedFolder(OrderItemServiceImpl.java:287)
  at com.defonds.syncpath.service.share.impl.ShareServiceImpl.handleRevokeSharedFolder(ShareServiceImpl.java:312)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at com.defonds.interfaceframework.controller.Action.invokeMethod(Action.java:256)
  at com.defonds.interfaceframework.controller.Action.execute(Action.java:206)
  at com.defonds.interfaceframework.controller.DispatcherServlet.service(DispatcherServlet.java:144)
  at com.defonds.syncpath.common.ArcSyncDispatcherServlet.service(ArcSyncDispatcherServlet.java:51)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
  at java.lang.Thread.run(Thread.java:619)

二、分析原因

Spring 事务嵌套造成死锁。OrderServiceImpl 里嵌入了 OrderItemService:

private OrderItemService orderItemService;
OrderServiceImpl 的 delete 方法里对 MySQL 的 Order 表有操作,而 OrderItemService 里的 revokeSharedFolder 方法也对同一张表有更新操作。事务嵌套,造成死锁。

三、解决方案

当前调用事务的方法设置为 Propagation.SUPPORTS:

@Transactional(propagation=Propagation.SUPPORTS)//by Defonds,for BUG094537
@Override
public void delete(int uid, int[] itemIds) {
  if (itemIds != null && itemIds.length > 0) {


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冰 河

可以吃鸡腿么?

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值