Statement cancelled due to timeout or client request 异常的修复【已解决】

Statement cancelled due to timeout or client request

报错详情

Caused by: com.mysql.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request 
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2303) 
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2696) 
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2105) 
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2398) 
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2316) 
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2301) 
at org.jboss.resource.adapter.jdbc.CachedPreparedStatement.executeUpdate(CachedPreparedStatement.java:95) 
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:251) 

报错分析及解决

在连接数据量比较大的表的时候,可能会报Statement cancelled due to timeout or client request 异常,在JDBC连接参数里加上queryTimeout=2400即可解决。

&queryTimeout=2400

问题重现及解决方案

上述方案治标不治本,所以Statement cancelled due to timeout or client request 卷土重来了

再加入上述参数过后,在数据量达到30w的时候selectByExample 又报这个错误,再经过分析,可能是:sql执行慢导致的阻塞,进而导致其他sql无法执行。

解决方案:

  1. 配置jdbc超时时间,适当增大
  2. 加索引,优化SQL,给关联字段增加索引
  3. 子查询尽量缩小搜索范围,减少join的次数
  4. 能用join就不要in了
  5. 限制索引的数目
  6. 不要查询*(所有),避免大字段,查询需要信息即可
  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 12
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

菜菜bu菜

夏日炎炎 有你超甜

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

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

打赏作者

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

抵扣说明:

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

余额充值