首页 技术 正文
技术 2022年11月17日
0 收藏 414 点赞 4,202 浏览 5162 个字

java.sql.SQLException: Lock wait timeout exceeded |  org.springframework.dao.CannotAcquireLockException 的解决

直接上 bug 的详细信息

  1. 2012-03-12 15:20:31 XmlBeanDefinitionReader [INFO] Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
  2. 2012-03-12 15:20:31 SQLErrorCodesFactory [INFO] SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
  3. 2012-03-12 15:20:31 ExceptionUtil [ERROR] SqlMapClient operation; SQL [];
  4. — The error occurred in com/defonds/syncpath/dao/operation.xml.
  5. — The error occurred while applying a parameter map.
  6. — Check the operation.updateShareStatus-InlineParameterMap.
  7. — Check the statement (update failed).
  8. — Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
  9. — The error occurred in com/defonds/syncpath/dao/operation.xml.
  10. — The error occurred while applying a parameter map.
  11. — Check the operation.updateShareStatus-InlineParameterMap.
  12. — Check the statement (update failed).
  13. — Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
  14. org.springframework.dao.CannotAcquireLockException: SqlMapClient operation; SQL [];
  15. — The error occurred in com/defonds/syncpath/dao/operation.xml.
  16. — The error occurred while applying a parameter map.
  17. — Check the operation.updateShareStatus-InlineParameterMap.
  18. — Check the statement (update failed).
  19. — Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
  20. — The error occurred in com/defonds/syncpath/dao/operation.xml.
  21. — The error occurred while applying a parameter map.
  22. — Check the operation.updateShareStatus-InlineParameterMap.
  23. — Check the statement (update failed).
  24. — Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
  25. at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:244)
  26. at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
  27. at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:212)
  28. at com.defonds.frameworkcommons.dao.BaseDaoImpl.execute(BaseDaoImpl.java:31)
  29. at com.defonds.frameworkcommons.dao.BaseDaoImpl.update(BaseDaoImpl.java:97)
  30. at com.defonds.syncpath.service.operation.impl.OperationServiceImpl.revokeSharedFolder(OperationServiceImpl.java:287)
  31. at com.defonds.syncpath.service.share.impl.ShareServiceImpl.handleRevokeSharedFolder(ShareServiceImpl.java:312)
  32. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  33. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  34. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  35. at java.lang.reflect.Method.invoke(Method.java:597)
  36. at com.defonds.interfaceframework.controller.Action.invokeMethod(Action.java:256)
  37. at com.defonds.interfaceframework.controller.Action.execute(Action.java:206)
  38. at com.defonds.interfaceframework.controller.DispatcherServlet.service(DispatcherServlet.java:144)
  39. at com.defonds.syncpath.common.ArcSyncDispatcherServlet.service(ArcSyncDispatcherServlet.java:51)
  40. at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  41. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
  42. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  43. at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
  44. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
  45. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  46. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  47. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
  48. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
  49. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
  50. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
  51. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
  52. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
  53. at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
  54. at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
  55. at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
  56. at java.lang.Thread.run(Thread.java:619)

分析原因

Spring 事务嵌套造成死锁。FileServiceImpl 里嵌入了 OperationService:

  1. private OperationService operationService;

FileServiceImpl 的 delete 方法里对 MySQL 的 file 表有操作,而 OperationService 里的 revokeSharedFolder 方法也对同一张表有更新操作。事务嵌套,造成死锁。

解决方案

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

    1. @Transactional(propagation=Propagation.SUPPORTS)//by Defonds,for BUG094537
    2. @Override
    3. public void delete(int uid, int[] itemIds) {
    4. if (itemIds != null && itemIds.length > 0) {
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,580
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918