springboot-connection pool(数据库连接池)

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

一.参考文献

1.1 springboot 1.57文档

二、配置

2.1 默认配置

Production database connections can also be auto-configured using a pooling DataSource. Here’s the algorithm for choosing a specific implementation:

  • We prefer the Tomcat pooling DataSource for its performance and concurrency, so if that is available we always choose it.
  • Otherwise, if HikariCP is available we will use it.
  • If neither the Tomcat pooling datasource nor HikariCP are available and if Commons DBCP is available we will use it, but we don’t recommend it in production and its support is deprecated.
  • Lastly, if Commons DBCP2 is available we will use it.

springboot默认用的是Tomcat连接池,如果配置了HikariCP,则自动用HiKariCP 

 

2.2 各种数据库连接池的application.properties配置

Tomcat连接池 spring.datasource.tomcat.*
hikari连接池 spring.datasource.hikari.*
dbcp2连接池 spring.datasource.dbcp2.*

例如:Tomcat

# Number of ms to wait before throwing an exception if no connection is available.
spring.datasource.tomcat.max-wait=10000

# Maximum number of active connections that can be allocated from this pool at the same time.
spring.datasource.tomcat.max-active=50

# Validate the connection before borrowing it from the pool.
spring.datasource.tomcat.test-on-borrow=true

 

2.3 如何配置 hikari数据库连接池?

第一步:加依赖


        
            com.zaxxer
            HikariCP
        

第二步:指定数据库连接池类型,由于默认是用Tomcat,所以需要在application.properties中配置

spring.datasource.type=com.zaxxer.hikari.HikariDataSource

第三步:配置hikari连接池具体属性

spring.datasource.hikari.maximum-pool-size=15
#其他的自己定制。。。。。

 

转载于:https://my.oschina.net/Cubicluo/blog/1542056

你可能感兴趣的:(springboot-connection pool(数据库连接池))