项目中遇到的死锁问题: Lock wait timeout exceeded; try restarting transaction
最近项目中频繁出现 Lock wait timeout exceeded; try restarting transaction这个错误,把我们弄得痛苦不堪啊,为了解决问题,上网上找好多资料,终于把问题复现了。具体操作步骤如下(我使用的mysql工具是 navicat):
第一步:开启sql命令页面
第二步:输入start transaction;开启一个事务
第三步:输入update语句 UPDATE TABLENAME set time=null where id=29163;(切记不要 提交(commit;))
第四步:书写测试类
public class StTest implements Runnable{
private static ApplicationContext applicationContext=null;
private static AtomicInteger a=new AtomicInteger(0);
static {
applicationContext=new ClassPathXmlApplicationContext("classpath:application.xml");
}
public static void main(String[] args) throws Exception {
ExecutorService executorService = Executors.newFixedThreadPool(10);
for (int i = 0; i <10 ; i++) {
executorService.execute(new aaaa());
}
if(!executorService.isTerminated()){
executorService.shutdown();
}
} @Override
public void run() {
XXXService bean = applicationContext.getBean(XXXService.class);
XXXBeand xx= null;
try {
xx= bean.byId(254213);
} catch (Exception e) {
e.printStackTrace();
}
long aaa=System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
try {
bean.update(xx);
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println(System.currentTimeMillis()-aaa);
}
}
运行程序并且运行下面3个sql查看结果
SELECT * FROM information_schema.INNODB_TRX;
select * from information_schema.innodb_lock_waits;
select * from information_schema.innodb_locks;
得到以下运行结果。我们发现有其他几个的 trx_state 状态是LOCK WAIT,得到我们要复现的结果
第五步:等待错误出现,在我们等待一段时间之后会发现程序报错
Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:995)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493)
at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:55)
at com.sun.proxy.$Proxy17.execute(Unknown Source)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:41)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:66)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:45)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:100)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75)
at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:59)
at com.sun.proxy.$Proxy15.update(Unknown Source)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:148)
at sun.reflect.GeneratedMethodAccessor34.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:354)
... 20 more
从上面得到的结果,可以知道这个错误是在一个事务没有提交的时候,其他事务也操作相同对象导致的,那么找到了问题的原因,我们就可以针对这种情况进行修改了。
这是本次我遇到的错误,分享给大家一下,以避免程序中遇到这样的情况。
项目中遇到的死锁问题: Lock wait timeout exceeded; try restarting transaction的更多相关文章
- 记录工作遇到的死锁问题(Lock wait timeout exceeded; try restarting transaction)
1.问题背景 刚来新公司不久,对业务还不太熟悉,所以领导先安排我维护原有系统.大概介绍下项目背景,项目分为核心业务部分在项目A中,与第三方交互的业务在项目B中,前端发起请求调用A项目接口,并在A项目中 ...
- 【问题解决:死锁】Lock wait timeout exceeded; try restarting transaction的问题
执行数据删除操作时一直超时并弹出Lock wait timeout exceeded; try restarting transaction错误 解决办法 1.先查看数据库的事务隔离级别 select ...
- mysql死锁,等待资源,事务锁,Lock wait timeout exceeded; try restarting transaction解决
前面已经了解了InnoDB关于在出现锁等待的时候,会根据参数innodb_lock_wait_timeout的配置,判断是否需要进行timeout的操作,本文档介绍在出现锁等待时候的查看及分析处理: ...
- 【mybatis】mybatis执行一个update方法,返回值为1,但是数据库中数据并未更新,粘贴sql语句直接在数据库执行,等待好久报错:Lock wait timeout exceeded; try restarting transaction
今天使用mybatis和jpa的过程中,发现这样一个问题: mybatis执行一个update方法,返回值为1,但是数据库中数据并未更新,粘贴sql语句直接在数据库执行,等待好久报错:Lock wai ...
- mysql Lock wait timeout exceeded; try restarting transaction解决
前面已经了解了InnoDB关于在出现锁等待的时候,会根据参数innodb_lock_wait_timeout的配置,判断是否需要进行timeout的操作,本文档介绍在出现锁等待时候的查看及分析处理: ...
- Mysql错误:ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
昨晚添加完索引之后, 查询整表的时候抛出Lock wait timeout exceeded; try restarting transaction, 吓死小白的我, 为什么条件查询可以, 整表查不了 ...
- java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction问题 1.问题描述 执行了几条update语句 ...
- MySQL应用报错:java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
开发反馈,某业务系统插入一条记录的时候,日志报错,插入失败: ### Error updating database. Cause: java.sql.SQLException: Lock wait ...
- com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction 问题解决
有两种设置方法 第一种在mysql的配置文件中加入,然后重启mysql innodb_lock_wait_timeout = 500 第二种直接执行如下命令 set global innodb_loc ...
随机推荐
- windows python文件拷贝到linux上执行问题-换行符问题/r/n
之前在Windows下写好了一个Python脚本,运行没问题,今天在Linux下,脚本开头的注释行已经指明了解释器的路径,也用chmod给了执行权限,但就是不能直接运行脚本. 1 问题1: 报错:: ...
- NGUI的UICamera
参考 https://blog.csdn.net/kakashi8841/article/details/20548429 全文请查看:http://note.youdao.com/notesha ...
- 虚拟机桥接网卡下配置centOS静态IP
前面我们讲了怎么去配置asterisk,但是配置完了,是没有什么效果出现的,因为asterisk相当于一个服务器,我们需要一个客户端去给它连接起来,如果你是在自己的机子上装了虚拟机,那最好配一下cen ...
- 安全人员常用的python库
如果你对漏洞挖掘.逆向工程分析或渗透测试感兴趣的话,我第一个要推荐给你的就是Python编程语言.Python不仅语法简单上手容易,而且它还有大量功能强大的库和程序可供我们使用.在这篇文章中,我们会给 ...
- Django前端的文本编辑器,滑动登陆
文本编译器 # 添加文章 url(r'^addarticle/$', views.addarticle), # 利用文本编辑器添加文章 def addarticle(request): ''' 添加文 ...
- phpstorm 不能提示代码tp 3.2 $this->display等 解决办法
phpstorm->file->Setting->Directorires 里把 ThinkPHP/Model 目录设置为 Excluded ,保存.
- Linux 上通过binlog文件 恢复mysql 数据库详细步骤
一.binlog 介绍 服务器的二进制日志记录着该数据库的所有增删改的操作日志(前提是要在自己的服务器上开启binlog),还包括了这些操作的执行时间.为了显示这些二进制内容,我们可以使用mysqlb ...
- 构造方法PK实例方法
1.构造方法 (1)用于对象初始化,一个类中至少有一个构造方法 (2)不能显示调用,只能在创建对象时,使用new来调用 (3)构造方法不能有返回值 (4)构造方法名称必须与类名一样 2.实例方法 (1 ...
- [js方法pk]之instanceof() vs isPrototypeOf() hasOwnProperty() vs propertyIsEnumerable()
这几个方法在js的高级编程中经常用到,对于新手来说可能还不知道他们有什么区别,我把我的体会总结下来,供大家参考: 首先,定义一个对象: function Parent() {this.name = & ...
- TRegEx 正则表达式
TRegEx #include <System.RegularExpressions.hpp> void __fastcall TForm1::Button1Click(TObject * ...