Spring Boot with default connection-pool

We Are Going To Discuss About Spring Boot with default connection-pool. So lets Start this Java Article.

Spring Boot with default connection-pool

Advertisements
  1. Spring Boot with default connection-pool

    Spring Boot uses the following algorithm for choosing a specific implementation:
    We prefer HikariCP for its performance and concurrency. If HikariCP is available, we always choose it.
    Otherwise, if the Tomcat pooling DataSource is available, we use it.
    Otherwise, if Commons DBCP2 is available, we use it.
    If none of HikariCP, Tomcat, and DBCP2 are available and if Oracle UCP is available, we use it.

  2. Spring Boot with default connection-pool

    Spring Boot uses the following algorithm for choosing a specific implementation:
    We prefer HikariCP for its performance and concurrency. If HikariCP is available, we always choose it.
    Otherwise, if the Tomcat pooling DataSource is available, we use it.
    Otherwise, if Commons DBCP2 is available, we use it.
    If none of HikariCP, Tomcat, and DBCP2 are available and if Oracle UCP is available, we use it.

Solution 1

Advertisements

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.

Original Author Of This Content

Solution 2

Advertisements

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

Original Author Of This Content

Conclusion

Advertisements

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Advertisements
Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment