使用Druid连接池,创建连接慢,以及后续访问,需要重新创建连接的问题!

rqenqsqc  于 5个月前  发布在  Druid
关注(0)|答案(1)|浏览(71)

这是我的连接池配置
#连接池的配置信息
initialSize: 10
minIdle: 10
maxActive: 30
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
maxEvictableIdleTimeMillis: 600000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: false
maxPoolPreparedStatementPerConnectionSize: 20
filters: stat,log4j
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000

下面是项目启动 首次访问数据库

  • (14649 ms) - [DEBUG] 2020-09-18 11:04:15,373 org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
  • (14651 ms) - [DEBUG] 2020-09-18 11:04:15,375 org.mybatis.spring.SqlSessionUtils - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1601838b] was not registered for synchronization because synchronization is not active
  • (19802 ms) - [DEBUG] 2020-09-18 11:04:20,526 druid.sql.Connection - {conn-10001} connected
  • (19863 ms) - [DEBUG] 2020-09-18 11:04:20,587 druid.sql.Connection - {conn-10002} connected
  • (19932 ms) - [DEBUG] 2020-09-18 11:04:20,656 druid.sql.Connection - {conn-10003} connected
  • (19994 ms) - [DEBUG] 2020-09-18 11:04:20,718 druid.sql.Connection - {conn-10004} connected
  • (25056 ms) - [DEBUG] 2020-09-18 11:04:25,780 druid.sql.Connection - {conn-10005} connected
  • (25117 ms) - [DEBUG] 2020-09-18 11:04:25,841 druid.sql.Connection - {conn-10006} connected
  • (25180 ms) - [DEBUG] 2020-09-18 11:04:25,904 druid.sql.Connection - {conn-10007} connected
  • (35240 ms) - [DEBUG] 2020-09-18 11:04:35,964 druid.sql.Connection - {conn-10008} connected
  • (40039 ms) - [DEBUG] 2020-09-18 11:04:40,763 druid.sql.Connection - {conn-10009} connected
  • (45101 ms) - [DEBUG] 2020-09-18 11:04:45,825 druid.sql.Connection - {conn-10010} connected
    大家注意看时间,创建10个连接要20S,网络没问题的,数据库也没问题

第二点 隔一段时间不访问,再次去访问后台,他又重新创建数据连接,代码如下

  • (3368512 ms) - [DEBUG] 2020-09-18 12:00:09,236 org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession
  • (3368512 ms) - [DEBUG] 2020-09-18 12:00:09,236 org.mybatis.spring.SqlSessionUtils - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5ee0c04d] was not registered for synchronization because synchronization is not active
  • (3368512 ms) - [DEBUG] 2020-09-18 12:00:09,236 druid.sql.Connection - {conn-10018} pool-connect

这样正常么?使用了连接池不应该是超时的连接报废,然后保持10个待使用连接么

7uzetpgm

7uzetpgm1#

默认是不保持连接,需要配置keepAlive,wiki 里面找keepAlive 这个参数

相关问题