AdBlock Detected

It looks like you're using an ad-blocker!

Our team work realy hard to produce quality content on this website and we noticed you have ad-blocking enabled. Advertisements and advertising enable us to continue working and provide high-quality content.

Hikari Spring Boot

In this post about Hikari Configuration in Spring Boot, we will see the implementation provided by Hikari to configure and parameterize our connection pool to databases.

What is Hikari?

Hikari offers a JDBC implementation that provides a connection pool to our database. Its main difference with other implementations we can find, apart from being fully integrated with Spring, is that it offers much better performance and is much lighter.

If you want to take a look at its project you can do it on its Github.

Hikari Configuration in a Spring Boot application

As mentioned earlier, Hikari integrates fully with Spring Boot applications. Obviously, the version of Hikari will depend on the version of your Spring Boot Parent, but if you still want the latest version of Hikari you can add it as a dependency in your pom.xml.

To add and override the default version of Hikari, simply add:

<dependency>
    <groupId>com.zaxxer</groupId>
    <artifactId>HikariCP</artifactId>
    <version>${version}</version>
</dependency>

Modifying Hikari configuration parameters in a Spring Boot application

Hikari offers a series of default values that should be sufficient for almost any application, but if you still need to modify those values to adapt them to your connection, let’s see what Hikari offers us:

Hikari’s ConnectionTimeout property

The property connectionTimeout indicates the maximum number of milliseconds that the service can wait to obtain a connection, defaulting to 30 seconds.

spring.datasource.hikari.connection-timeout: 20000

Hikari’s minimumIdle property

The minimumIdle property in Hikari represents the minimum number of inactive connections that the connection pool can maintain. The default number is 10.

spring.datasource.hikari.minimum-idle: 15

Hikari’s maxLifetime property

The maxLifetime property of Hikari specifies the time, in milliseconds, that a connection can remain in use after being closed. Be careful not to set a very high time.

spring.datasource.hikari.max-lifetime: 120000

Hikari’s maximumPoolSize property

The maximumPoolSize property indicates the maximum size we will have in the connection pool. The default value is 10.

spring.datasource.hikari.maximum-pool-size: 7 

IdleTimeout configuration in Hikari

The idleTimeout configuration is the maximum time we will allow a connection to be inactive in the connection pool.

spring.datasource.hikari.idle-timeout: 300000 

Hikari’s autoCommit property

This property establishes automatic confirmation of connections that the connection pool returns. If it is not modified, it will have a default value of TRUE.

spring.datasource.hikari.auto-commit: false 
Hikari Configuration in Spring Boot
Example Hikari configuration

Keep in mind that you can use – or uppercase letters.

Conclusion

In this article, we have seen how to use Hikari configuration in Spring Boot, looking at the different values and parameters that we can configure.

Hikari is an excellent choice for handling connection pools in Java applications, and its use can significantly improve performance and efficiency in managing database connections. Additionally, integration with Spring Boot makes configuration very simple and flexible.

If you need more information, you can leave us a comment or send an email to refactorizando.web@gmail.com You can also contact us through our social media channels on Facebook or twitter and we will be happy to assist you!!

Leave a Reply

Your email address will not be published. Required fields are marked *