Spring Boot with default connection-pool
Asked Answered
M

2

14

I'm using SpringBoot (v2.3.0.RELEASE), JPA and Hibernate (with a MySQL database). I need to try to improve, in general, the performances.

It's not completely clear for me if, into the default configuration, is already there a Database Connection Pool.

I didn't add any specific dependencies into my pom about a connection pool but when I try to run my service I read:

2021-07-01 13:53:04.065  INFO  HikariDataSource-getConnection():110 - [ HikariPool-1 - Starting... ]
2021-07-01 13:53:04.499  INFO  HikariDataSource-getConnection():123 - [ HikariPool-1 - Start completed. ]

can you give me some info about this?

Do I need to configure (adding the dependency also) a connection pool manually?

Mckibben answered 6/7, 2021 at 10:4 Comment(2)
There is already a connection pool so no you don't need to add one (this is also explained in the reference guide). You can still configure it by increasing the max connections (the default is 10 for instance).Caputto
ok, thanks ... can you give me the link to the reference guide please?Mckibben
A
27

Hikari is the default DataSource implementation with Spring Boot 2. This means we need not add explicit dependency in the pom.xml. The spring-boot-starter-jdbc and spring-boot-starter-data-jpa resolve it by default. To sum up, you require no other steps with Spring Boot 2.
Link for Documentation : Spring Documentation for Connection pools

Although you modify the default properties of HikariCP

spring.datasource.hikari.connection-timeout = 20000 #maximum number of milliseconds that a client will wait for a connection

spring.datasource.hikari.minimum-idle= 10 #minimum number of idle connections maintained by HikariCP in a connection pool

spring.datasource.hikari.maximum-pool-size= 10 #maximum pool size

spring.datasource.hikari.idle-timeout=10000 #maximum idle time for connection

spring.datasource.hikari.max-lifetime= 1000 # maximum lifetime in milliseconds of a connection in the pool after it is closed.

spring.datasource.hikari.auto-commit =true #default auto-commit behavior.
Abscission answered 6/7, 2021 at 11:51 Comment(0)
A
8

As per Spring Boot Documentation:

Supported Connection Pools:-

Spring Boot uses the following algorithm for choosing a specific implementation:

  1. We prefer HikariCP for its performance and concurrency. If HikariCP is available, we always choose it.
  2. Otherwise, if the Tomcat pooling DataSource is available, we use it.
  3. Otherwise, if Commons DBCP2 is available, we use it.
  4. If none of HikariCP, Tomcat, and DBCP2 are available and if Oracle UCP is available, we use it.

If you use the spring-boot-starter-jdbc or spring-boot-starter-data-jpa “starters”, you automatically get a dependency to HikariCP.

Spring documentation

Have a look into HikariCP: https://github.com/brettwooldridge/HikariCP

Activator answered 6/7, 2021 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.