Java.HikaryCP.What is the purpose of leakDetectionThreshold and when should you use it?

Purpose:
The leakDetectionThreshold setting in HikariCP helps detect connection leaks — cases when your application borrows a connection from the pool but forgets to close it.
If a connection remains open (checked out) longer than the configured threshold, HikariCP logs a stack trace of where the connection was acquired, helping you pinpoint the leak source.

Usage:
Use it when you suspect connection leaks, or as a best practice in critical systems where connection leaks could exhaust the pool and cause downtime. It’s a valuable tool in QA and staging environments, or in production with a reasonable threshold that avoids false positives.

Example:

spring.datasource.hikari.leak-detection-threshold=15000

This config means if a connection is held longer than 15 seconds, HikariCP will log a warning with the stack trace showing where the connection was checked out.

Important note:
Setting the threshold too low may result in false positives (e.g., during long-running queries). Choose a value slightly longer than your longest expected query execution time.

This entry was posted in Без рубрики. Bookmark the permalink.

Leave a Reply

Your email address will not be published.