Just_another_developer
Just_another_developer

Reputation: 5955

SpringBoot and HikariCP relationship

SpringBoot already is managing dataConnection then why is Hikari CP needed?

I have just started using SpringBoot so do not know much about SpringBoot and Hikari relation, although i read about Hikari but couldn't find any explicit explanation about its relationship with Springboot in presence of Spring data connection.

I read that Hikari is used when we need heavy db operations with lots of connections, if it is true then should we not use Hikari in follwoing scenario?

Scenario:

There is a small application, having maximum 8-10 REST calls once in a month or maximum fortnightly.That application needs to perform some probability and statistics related calculation.

Users login on that app at a time are of maximum 2-3 in numbers.

Do we still need to use Hikari?

Upvotes: 2

Views: 1313

Answers (3)

Amro Nahas
Amro Nahas

Reputation: 54

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. Compared to other implementations, it promises to be lightweight and better performing.

Tuning Hikari Configuration Parameters:

  • 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.

HikariCP is a reliable, high-performance JDBC connection pool. It is much faster, lightweight, and has better performance as compared to other connection pool APIs. Because of all these compelling reasons, HikariCP is now the default pool implementation in Spring Boot 2. In this article, we will have a closer look to configure Hikari with Spring Boot.

Upvotes: 1

Nikem
Nikem

Reputation: 5784

There are two ways to communicate with the database from your application. You can either open a new DB connection any time you wish execute some query there, or you have a connection pool. Connection pool is a collection of reusable connections that application uses for DB communication. As establishing a new connection is relatively expensive operation, using connection pool gives you a significant performance improvement.

HikariCP is one of the connection pools libraries available in java and SpringBoot uses it as a default. As you don't need to do anything special to have it in your application, just enjoy your free lunch :)

Upvotes: 2

ahmetcetin
ahmetcetin

Reputation: 2970

HikariCP is used as the default connection pool in SpringBoot2, it was TomcatJDBC in SpringBoot 1. You must be using it as a default in your settings. You can overwrite it by setting another connection pool in your setting properties if you need. Please find more details about the connection pools and the default configurations of Spring Boot versions here.

Upvotes: 1

Related Questions