brettwooldridge / HikariCP

光 HikariCP・A solid, high-performance, JDBC connection pool at last.
Apache License 2.0
19.63k stars 2.9k forks source link

Developer experience: allow configuring HikariCP with `java.time.Duration` instead of millisecond / second parameters #2191

Open hiddewie opened 2 months ago

hiddewie commented 2 months ago

Currently, configuring the idleTimeout property of the connection pool will use the setIdleTimeout method on the HikariConfig configuration class.

Similarly, many of the other configuration parameters are duration values. The values range from millisecond, to second, to minute. This difference in order of magnitude can make it error-prone to configure the connection pool correctly, and review the configured values.

It would be great to be able to configure the connection pool using java.time.Duration values, for example

configuration.setIdleTimeout(Duration.ofMinutes(5))
configuration.setIdleTimeout(Duration.ofSeconds(10))

This makes the intent clear of the code more clear than the current

configuration.setIdleTimeout(300000)
configuration.setIdleTimeout(5 * 60 * 1000)
configuration.setIdleTimeout(10000) // 10 seconds, or did I make a typo got a zero too much or too little?

I am willing to build a pull request if this feature is found to be useful.

Implementation seems to be extending the HikariConfigMXBean with extra setter methods, and extending the implementation HikariConfig.

Furthermore, PropertyElf could be extended to take into account property values of the same syntax, for example:

# 5 minutes idle timeout, all properties are equivalent
idleTimeout = 300000 
idleTimeout = 300s
idleTimeout = 5m