SpringBoot found major issues with the latest version of Druid

Druid problem found

I recently worked on a project and encountered a lot of insertions. After a lot of debugging, I finally found that it was a problem with the Druid connection pool. (I encountered Druid's pit in a large project before). After decisively changing to c3p0, the stress test went up. Up.

The following is how to replace c3p0.

1. Modify pom.xml

Import c3p0 dependencies:

<dependency>
    <groupId>com.mchange</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.5.5</version>
</dependency>

2. Modify application.yml

spring:
  application:
    name: nh-tst
  http:
    encoding:
      charset: UTF-8
      enabled: true
      force: true
  datasource:
    driver-class-name: oracle.jdbc.driver.OracleDriver
  jpa:
    hibernate:
      ddl-auto: none
    show-sql: true
c3p0:
  jdbcUrl: jdbc:oracle:thin:@xxxxx:1522/prodpdb1
  user: xxxxxx
  password: xxxxxx
  driverClass: oracle.jdbc.driver.OracleDriver
  minPoolSize: 3
  maxPoolSize: 30
  maxIdleTime: 1800000
  acquireIncrement: 120
  maxStatements: 100000
  initialPoolSize: 5
  idleConnectionTestPeriod: 60
  acquireRetryAttempts: 30
  acquireRetryDelay: 10000
  breakAfterAcquireFailure: false
  testConnectionOnCheckout: false

3. Increase the DataSourceConfiguration.java class

package com.nh.fk.tst.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import com.mchange.v2.c3p0.ComboPooledDataSource;

@Configuration
public class DataSourceConfiguration {
    
    
	// c3p0 连接池
	@Bean(name = "dataSource")
	@Qualifier(value = "dataSource")
	@Primary
	@ConfigurationProperties(prefix = "c3p0")
	public DataSource dataSource() {
    
    
		return DataSourceBuilder.create().type(ComboPooledDataSource.class).build();
	}
}

Pack and execute: the world is at peace again! !

Guess you like

Origin blog.csdn.net/u014745631/article/details/108786050