Class HikariStatusProvider
- All Implemented Interfaces:
HealthProvider,StatusProvider,SmartInitializingSingleton
StatusProvider, for each pool, named after its
data source bean, the connections in use out of the most the pool opens, and the threads waiting for a connection, such as
dataSource: 7/10 connections, 3 waiting, and as a HealthProvider, for the systemd watchdog, reporting the application as unhealthy while
a pool is starved, if enabled.
The pools are those of the DataSource beans that are, or wrap, a HikariDataSource, found once all singleton beans are created, so
that lazy ones are not created. A data source whose pool is not started yet, as Hikari only starts it on the first
connection, is left out until then.
The health is enabled on its own, as it lets systemd restart the application: while disabled, the application is always healthy. When enabled, it is
unhealthy while any pool is starved: all its connections are in use, and threads are waiting for one, naming the starved data sources in the health
details, under starvedDataSources. A starved pool usually means connections leak, as code that takes a connection never gives it back, which
only a restart recovers from. As a burst of requests can also starve a pool for a while, the unhealthy state should be delayed, with
DelayableHealthProvider.setUnhealthyDelay(java.time.Duration): the pool must then stay starved, every time the health is evaluated, for that long.
A database that cannot be reached does not starve the pools: their threads wait for a connection, but the connections are not in use, as the pools cannot open them. That is left for the health indicators of Spring Boot Actuator.
- Author:
- Joao Silva
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.github.jpmsilva.jsystemd.HealthProvider
HealthProvider.Health -
Constructor Summary
ConstructorsConstructorDescriptionHikariStatusProvider(ConfigurableListableBeanFactory beanFactory, boolean health) Creates a new instance that finds the data sources in the given bean factory. -
Method Summary
Modifier and TypeMethodDescriptionvoidFinds the HikariCP connection pools among the data source beans that are already created.protected HealthProvider.HealthProvides the health of the application, without the delay: unhealthy while any pool is starved, if enabled.status()Exposes status information to send to systemd.Methods inherited from class com.github.jpmsilva.jsystemd.DelayableHealthProvider
getUnhealthyDelay, health, setUnhealthyDelay
-
Constructor Details
-
HikariStatusProvider
Creates a new instance that finds the data sources in the given bean factory.- Parameters:
beanFactory- the bean factory to find the data sources inhealth-trueto report the application as unhealthy while any pool is starved
-
-
Method Details
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()Finds the HikariCP connection pools among the data source beans that are already created.- Specified by:
afterSingletonsInstantiatedin interfaceSmartInitializingSingleton
-
status
Description copied from interface:StatusProviderExposes status information to send to systemd.- Specified by:
statusin interfaceStatusProvider- Returns:
- the string message to add to the service status
-
evaluateHealth
Provides the health of the application, without the delay: unhealthy while any pool is starved, if enabled.- Specified by:
evaluateHealthin classDelayableHealthProvider- Returns:
- the health of the application
-