Class ThreadStatusProvider

java.lang.Object
com.github.jpmsilva.jsystemd.ThreadStatusProvider
All Implemented Interfaces:
HealthProvider, StatusProvider

public class ThreadStatusProvider extends Object implements StatusProvider, HealthProvider
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 the DelayableHealthProvider ones: 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
  • Constructor Details

    • ThreadStatusProvider

      public ThreadStatusProvider(boolean detectDeadlocks, boolean deadlockHealth)
      Create a new ThreadStatusProvider.
      Parameters:
      detectDeadlocks - true to also detect deadlocked threads, reporting them in the status
      deadlockHealth - true to 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

      public String status()
      Description copied from interface: StatusProvider
      Exposes status information to send to systemd.
      Specified by:
      status in interface StatusProvider
      Returns:
      the string message to add to the service status
    • health

      public HealthProvider.Health health()
      Reports the application as unhealthy while any of the enabled health conditions holds. Always healthy when none is enabled.
      Specified by:
      health in interface HealthProvider
      Returns:
      the health of the application