Package com.github.jpmsilva.jsystemd
Class ThreadStatusProvider
java.lang.Object
com.github.jpmsilva.jsystemd.ThreadStatusProvider
- All Implemented Interfaces:
HealthProvider,StatusProvider
Provides information regarding the live threads: as a
StatusProvider, the number of threads by state, and the number of deadlocked
threads, if any, for the systemd status, and as a HealthProvider, for the systemd watchdog, reporting the application as unhealthy under the
health conditions it is configured with.
Only platform threads are reported: virtual threads are not visible through ThreadMXBean.
Each health condition is enabled on its own, and the application is healthy while none of the enabled ones holds, which is always the case when none is enabled. The health conditions are:
- deadlock health: unhealthy while any thread is deadlocked, naming the deadlocked threads in the health details, under
deadlockedThreads. Requires deadlock detection. As a deadlock never resolves by itself, the unhealthy state is not delayed, unlike theDelayableHealthProviderones: delaying the restart would only delay the recovery.
Both reading the thread states and detecting deadlocks pause the JVM briefly at a safepoint, for a time that grows with the number of threads. This is negligible at the usual status update and watchdog periods.
- Author:
- Joao Silva
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.github.jpmsilva.jsystemd.HealthProvider
HealthProvider.Health -
Constructor Summary
ConstructorsConstructorDescriptionThreadStatusProvider(boolean detectDeadlocks, boolean deadlockHealth) Create a new ThreadStatusProvider. -
Method Summary
-
Constructor Details
-
ThreadStatusProvider
public ThreadStatusProvider(boolean detectDeadlocks, boolean deadlockHealth) Create a new ThreadStatusProvider.- Parameters:
detectDeadlocks-trueto also detect deadlocked threads, reporting them in the statusdeadlockHealth-trueto report the application as unhealthy while any thread is deadlocked, which requires detecting deadlocks- Throws:
IllegalArgumentException- if deadlock health is enabled without detecting deadlocks
-
-
Method Details
-
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
-
health
Reports the application as unhealthy while any of the enabled health conditions holds. Always healthy when none is enabled.- Specified by:
healthin interfaceHealthProvider- Returns:
- the health of the application
-