alibaba / druid

阿里云计算平台DataWorks(https://help.aliyun.com/document_detail/137663.html) 团队出品,为监控而生的数据库连接池
https://github.com/alibaba/druid/wiki
Apache License 2.0
27.9k stars 8.57k forks source link

[BUG] mysql-connector-j 8.2.0以后,项目启动时间变长 #6063

Open xiaoxiaozai opened 1 month ago

xiaoxiaozai commented 1 month ago

Database Type

mysql

Database Version

mysql8

Druid Version

1.2.23

JDK Version

8

Error SQL

select 1

Testcase Code

No response

Stacktrace Info

No response

Error Info

pom文件依赖如下:

org.springframework.boot spring-boot-starter 2.7.18
    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-boot-starter</artifactId>
        <version>3.5.3.1</version>
    </dependency>
    <dependency>
        <groupId>com.mysql</groupId>
        <artifactId>mysql-connector-j</artifactId>
        <version>9.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.2.23</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>

properties配置如下: spring.datasource.druid.username=xxxxx spring.datasource.druid.password=xxxxxx spring.datasource.druid.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.druid.url=jdbc:mysql://xxxx:3306/test?useSSL=false&serverTimezone=GMT%2B8 spring.datasource.druid.validation-query= select 1 spring.datasource.druid.initial-size=10 spring.datasource.druid.max-active=10 spring.datasource.druid.connect-timeout=-1 spring.datasource.druid.socket-timeout=-1 spring.datasource.druid.filter.slf4j.enabled=true spring.datasource.druid.filter.stat.enabled=true spring.datasource.druid.stat-view-servlet.enabled=true spring.datasource.druid.web-stat-filter.enabled=true

spring.datasource.druid.connection-init-sqls=SET NAMES utf8mb4,SET NAMES utf8mb4

卡顿现象: 启动时间过长,卡在 2024-07-25 16:52:10.796 INFO 17032 --- [ main] c.a.d.s.b.a.DruidDataSourceAutoConfigure : Init DruidDataSource 2024-07-25 16:53:52.894 INFO 17032 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited 这个位置. 启动时长随initial-size 的大小变化而变化.默认启动1个-3个实例的话,等待时间可以接受,默认启动10个会等待很久. 在mysql-connector-j 8.2.0以后出现的问题. 8.2.0及之前都没有这个现象.想请教一下这个问题怎么解决.

HaoHaoDaYouXi commented 1 week ago

可以添加异步初始化spring.datasource.druid.asyncInit=true