日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

mysql并发插入死锁_高并发下insert死锁 · Issue #ITUNR · baomidou/mybatis-plus - Gitee.com...

發(fā)布時間:2025/3/21 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql并发插入死锁_高并发下insert死锁 · Issue #ITUNR · baomidou/mybatis-plus - Gitee.com... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

當前使用版本(必須填寫清楚,否則不予處理)

springboot版本:2.0.3.RELEASE

mybatis版本:3.0.5

jdk:1.8

該問題是怎么引起的?(最新版上已修復的會直接close掉)

public Result getExamSetByExamId(@RequestParam("useTime")String useTime,

@RequestParam("openId")String openId,

@RequestParam("score")String score,

@RequestParam("isPass")Integer isPass,

@RequestParam("resultCount")Integer resultCount,

@RequestParam("answer")String answer){

try{

List resultToday = resultEverydayService.findResultToday(openId);

if(!resultToday.isEmpty()){

return ResultUtils.error(0001,"該賬號已經(jīng)答過題,請勿重復提交");

}

ResultEveryday resultEveryday = new ResultEveryday();

resultEveryday.setScore(Integer.valueOf(score)).setOpenId(openId).

setIsPass(isPass).setUseTime(useTime).setResultCount(resultCount);

resultEverydayService.save(resultEveryday);

resultDetailsEveryDay(resultEveryday.getResultId(),answer);

return ResultUtils.success(resultEveryday.getResultId());

}catch (Exception e){

log.error(openId+",提交每日答題失敗,{}",e);

return ResultUtils.error(0001,"提交失敗");

}

}

數(shù)據(jù)庫操作有兩次,第一次是查詢

List resultToday = resultEverydayService.findResultToday(openId);

第二次是新增

resultEverydayService.save(resultEveryday);

操作的是同一張表,先查詢是否已經(jīng)有,沒有的話進行新增

重現(xiàn)步驟

當并發(fā)的時候出現(xiàn)此類錯誤

報錯信息

Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction

The error may involve com.mybatis.plus.mp.mapper.ResultEverydayMapper.insert-Inline

The error occurred while setting parameters

SQL: INSERT INTO mp_result_everyday ( open_id, use_time, is_pass, score, result_count ) VALUES ( ?, ?, ?, ?, ? )

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction

; ]; Lock wait timeout exceeded; try restarting transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction

總結

以上是生活随笔為你收集整理的mysql并发插入死锁_高并发下insert死锁 · Issue #ITUNR · baomidou/mybatis-plus - Gitee.com...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。