添加链接池后批量添加更新出现了死锁

org.springframework.dao.DeadlockLoserDataAccessException:
### Error updating database. Cause: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
### The error may exist in file [E:\java\project\bim-service\target\classes\mapper\ApiPropertiesMapper.xml]
### The error may involve com.tydt.bim.dao.ApiPropertiesMapper.batchAddProperties-Inline
### The error occurred while setting parameters
### SQL: insert into api_properties (`guid`,`name`,`file_id`,`value`,`unit`) values (?,?,?,?,?) , (?,?,?,?,?) , (?,?,?,?,?) , (?,?,?,?,?) , (?,?,?,?,?) ON DUPLICATE KEY UPDATE `value`=values(`value`),`unit`=values(`unit`)
### Cause: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
; Deadlock found when trying to get lock; try restarting transaction; nested exception is com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction

INSERT ON DUPLICATE KEY在执行时,innodb引擎会先判断插入的行是否产生重复key错误

如果存在,在对该现有的行加上S(共享锁)锁,返回该行数据给mysql,然后mysql执行完duplicate后的update操作,然后对该记录加上X(排他锁),最后进行update写入

如果有两个事务并发的执行同样的语句,那么就会产生death lock

解决方法:

1、尽量不对存在多个组合唯一键的table上使用该语句

2、在有可能有并发事务执行的insert 的内容一样情况下不使用该语句

  先用select查看是否存在,再决定是insert还是update,但是这样耗时比较多

解决org.springframework.dao.DeadlockLoserDataAccessException的更多相关文章

  1. Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Multiple representations of the same entity解决方法

    1.错误信息 Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUs ...

  2. java.lang.NoClassDefFoundError: org/springframework/dao/support/PersistenceE解决方法

    笔者是使用spring4.0时,报的错误: 原因是没有引入spring-tx-4.0.0.RELEASE.jar包,將spring-tx-4.0.0.RELEASE.jar添加到build path中 ...

  3. org.springframework.dao.DataIntegrityViolationException:

    数据库用的hibernate,开发工具用的myeclipse,使用开发工具连接数据库生成hibernate基于xml的po类,运行时报org.springframework.dao.DataInteg ...

  4. javaEE-----org.springframework.dao.InvalidDataAccessApiUsageException: Write operation

    org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read ...

  5. org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [41] did not match expected type [java.lang.Integer (n/a)];

    题记:以前记录过一些自己遇到的BUG,这个行为,让我一看报错的提示信息就能定位到问题的所在,后来记得比较多了,好多是重复性的再加上比较忙就没有详细的记录了,今天的工作量比较小,就顺便记录一下,以便以后 ...

  6. OpenSessionInViewFilter与org.springframework.dao.InvalidDataAccessApiUsageException

    报错:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in r ...

  7. org.springframework.dao.EmptyResultDataAccessException

    public Wcrash getWcrashInfo(int id) { String sql = "select plateform_id,android_version,app_ver ...

  8. org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist: sys.entity.Role; nested exception is org.hibernate.PersistentObjectException: 的解决方案

    1.错误信息 org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist ...

  9. org.springframework.dao.InvalidDataAccessApiUsageException报错

    2018-01-09 18:12:29,980 [qtp1501019626-21] ERROR - 外部接口调用方法[TestController$$EnhancerBySpringCGLIB$$8 ...

随机推荐

  1. linux中/dev/null与2>&1讲解

    首先先来看下几种标识的含义: /dev/null 表示空设备文件 0 表示stdin标准输入 1 表示stdout标准输出 2 表示stderr标准错误 先看/dev/null command > ...

  2. 17、Python面向对象高级

    一.isinstance和issubclass type():不会认为子类实例是一种父类类型: isinstance():认为子类实例是一种父类类型. issubclass():判断是否为其子类. c ...

  3. 如果wordpress分类只有一篇文章则直接跳转到文章页

    每个项目的需求都不一样,比如最近ytkah的客户提出如果wordpress分类只有一篇文章则直接跳转到文章页,这个实现起来不会很麻烦,几行代码就能搞定,下面就来一起看看吧.打开主题的function. ...

  4. Python下编写Windows自动化测试软件

    https://www.jianshu.com/p/be3c46c7a905 uiautomation模块学习笔记 前段时间,由于个人需要,在网上查找了一些关于Windows平台下自动化测试的资料,最 ...

  5. hdu2068-RPG的错排-(dp递推式)

    去年看错排公式,死都看不懂,基础扎实之后再来看就略懂了. 公式: dp[ n ] = ( n-1 ) * ( dp[n-1] + dp[n-2] ) 解析公式:比如有n个元素,各对应n个正确位置,dp ...

  6. python - django 设置自定义文件保存路径

    一. settings.py MEDIA_URL = "/qir/" # 设置获取文件时的访问根路径 MEDIA_ROOT = os.path.join(BASE_DIR, &qu ...

  7. java 面向对象2

    1.  类是对某一类事物的抽象描述,而对象用于表示现实中该类事物的个体. 玩具模型是类: 玩具是对象: ★局部变量和成员变量的区别: 区别一:定义的位置不同 定义在类中的变量是成员变量 定义在方法中或 ...

  8. spl_autoload_register 和 __autoload()魔术方法

    在 PHP 5.3 之前,__autoload 函数抛出的异常不能被 catch 语句块捕获并会导致一个致命错误(Fatal Error).  尽管 __autoload() 函数也能自动加载类和接口 ...

  9. [Cqoi2016]K远点对 K-Dtree

    4520: [Cqoi2016]K远点对 链接 bzoj 思路 用K-Dtree求点的最远距离. 求的时候顺便维护一个大小为2k的小根堆. 不知道为啥一定会对. 代码 #include <bit ...

  10. uni-app 项目记录

    await等候,等待:期待 什么是async.awaitawait 用于等待异步完成通常async.await都是跟随Promise一起使用的 async返回的都是一个Promise对象同时async ...