user1638172
user1638172

Reputation: 123

Spring boot hikaricp connection-timeout vs connectionTimeout

when I google the Hikaricp connection properties, I found two major difference, for example:

https://www.javadevjournal.com/spring-boot/spring-boot-hikari/

https://www.baeldung.com/spring-boot-hikari

spring.datasource.hikari.connection-timeout = 20000
spring.datasource.hikari.connectionTimeout=30000

when I look into https://github.com/brettwooldridge/HikariCP#configuration-knobs-baby

I cannot find '''.connection-timeout'''

what is the difference between connection-timeout vs connectionTimeout?

this is one of the difference I found on net. 😒

Upvotes: 5

Views: 26835

Answers (2)

M. Deinum
M. Deinum

Reputation: 124506

Spring Boot utilized something they call relaxed binding and each of those properties would endup in the same place. The connectionTimeout property of the HikariDataSource.

In fact you could also use _ or when providing a environment variable use uppercase names.

spring.datasource.hikari.connection-timeout=20000
spring.datasource.hikari.connection_timeout=20000
spring.datasource.hikari.connectionTimeout=30000
SPRING_DATASOURCE_HIKARI_CONNECTIONTIMEOUT=30000

All of the aforementioned properties would eventually be bound to the HikariDataSource.connectionTimeout property. They are all different representations of the same. The latter is mainly to overcome the limitation of not being able to use - in environment variables in Linux/Mac.

Upvotes: 12

Shailendra
Shailendra

Reputation: 9102

Here is the actual code in Hikari - setting up the configuration and the actual property is connectionTimeout. Spring would most likely invoke it via setter when provided this setting in Spring configuration

public class HikariConfig implements HikariConfigMXBean
{
.....................
.....................

private volatile long connectionTimeout;

/** {@inheritDoc} */
   @Override
   public long getConnectionTimeout()
   {
      return connectionTimeout;
   }

   /** {@inheritDoc} */
   @Override
   public void setConnectionTimeout(long connectionTimeoutMs)
   {
      if (connectionTimeoutMs == 0) {
         this.connectionTimeout = Integer.MAX_VALUE;
      }
      else if (connectionTimeoutMs < 250) {
         throw new IllegalArgumentException("connectionTimeout cannot be less than 250ms");
      }
      else {
         this.connectionTimeout = connectionTimeoutMs;
      }
   }

Upvotes: 0

Related Questions