I have a little confused about maxLifetime configuration. In hikari, there is a housekeeping to check idleTimeout of each connection periodically, so when should I use the maxLifetime?
In a busy pool, connections are likely to never reach their _idleTimeout_. However, many firewalls and load-balancers, that often lie between an application and the database, impose socket lifetimes. Often, when this lifetime is reached, the connection is cut regardless of current traffic.
However, probably the primary reason to cycle connections periodically is as a guard against memory leaks. Databases often have resources (caches, file-handles, meta-data) attached to a connection, and if a connection is _never_ retired then resource leaks are magnified over time. And even JDBC drivers have been known to leak.
Most helpful comment
In a busy pool, connections are likely to never reach their _idleTimeout_. However, many firewalls and load-balancers, that often lie between an application and the database, impose socket lifetimes. Often, when this lifetime is reached, the connection is cut regardless of current traffic.
However, probably the primary reason to cycle connections periodically is as a guard against memory leaks. Databases often have resources (caches, file-handles, meta-data) attached to a connection, and if a connection is _never_ retired then resource leaks are magnified over time. And even JDBC drivers have been known to leak.