CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; request timed out after 30000ms

本文讲述了在业务开发中遇到的ConnectionException和requesttimeout问题,通过分析Durid数据连接池配置和SQL查询优化,特别是对Mysql数据库的连接管理,解决查询速度变慢引发的线上问题。
摘要由CSDN通过智能技术生成

  今天在编辑业务开发,发布到测试环境时,看到个关于 ConnectionException 的问题;随便操作 DB 任意事件发现就报 request timed out ,经过 慢长的 ......SQL 分析定义,小结 2 点如下:

1. 数据连接池的  Durid 配置

spring:
  datasource:
    # 使用了多数据源方式,单个的话 dynamic 到 datasource 中间层(即标识 `# A` 的)可以移除
    dynamic: # A
      primary: master # A
      strict: false # A
      datasource: # A
        text_db:
          # 注:这是 Mysql connection 8.0 以上的驱动
          driver-class-name: com.mysql.cj.jdbc.Driver  
          url: jdbc:mysql://xxx:3306/ucd?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
          username: tpple
          password: 67evCVe2!ivx
          druid:
            initialSize: 25
            maxActive: 200
            minIdle: 50
            maxWait: 60000
            poolPreparedStatements: true
            maxPoolPreparedStatementPerConnectionSize: 100
            maxOpenPreparedStatements: 100
            removeAbandonedTimeout: 1800
            logAbandoned: true
            removeAbandoned: true
            validationQuery: SELECT 'x'
            testWhileIdle: true
            testOnBorrow: true
            testOnReturn: false
            timeBetweenEvictionRunsMillis: 60000
            minEvictableIdleTimeMillis: 300000
            filters: stat,wall,slf4j
            useUnfairLock: true

2. 查询的 SQL 语句是否走了索引 — 关键(一开始工程从 0-1 看似乎使用正常,随着一定的时间周期会越来越慢,在不知觉的情况下甚至产生线上连锁问题) 

        报的对应的 查询方法添加了相关索引,问题就没有出现;

Tip:仅供排查问题参考,相同问题、相似异常提示,在实际开发中是由不同的原因导致的;

异常如下: 

### Error querying database. Cause: oxg.sRringframework.jake.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is
jaxa.sal.slTransientConnectionException: master - Connection is not available, request timed out after 30000ms.
### The error may exist in con/tmah/saag/data/domain/mxkatis/mapper/DataPushLogBodyMapper.1axa (best guess)
### The error may involve gom.tmzh.saas.data.domain.mxbatis.mapper.DataPushLogBodyMapper.selectList
### The error occurred while executing a query
### Cause: omg.apringtramework.1dbe.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is
jaxa.sl.sQLTransientConnectionException: master - Connection is not available, request timed out after 30000ms.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值