|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2018, 2023 Oracle and/or its affiliates. |
| 2 | + * Copyright (c) 2018, 2025 Oracle and/or its affiliates. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
19 | 19 | import java.lang.System.Logger.Level;
|
20 | 20 | import java.lang.management.ManagementFactory;
|
21 | 21 | import java.lang.management.ThreadMXBean;
|
| 22 | +import java.util.Arrays; |
22 | 23 |
|
23 | 24 | import io.helidon.common.NativeImageHelper;
|
24 | 25 | import io.helidon.health.HealthCheck;
|
@@ -95,17 +96,22 @@ public HealthCheckResponse call() {
|
95 | 96 | .build();
|
96 | 97 | }
|
97 | 98 |
|
98 |
| - boolean noDeadLock = false; |
| 99 | + HealthCheckResponse.Builder builder = HealthCheckResponse.builder(); |
| 100 | + |
99 | 101 | try {
|
100 | 102 | // Thanks to https://stackoverflow.com/questions/1102359/programmatic-deadlock-detection-in-java#1102410
|
101 |
| - noDeadLock = (threadBean.findDeadlockedThreads() == null); |
| 103 | + long[] deadlockedThreads = threadBean.findDeadlockedThreads(); |
| 104 | + if (deadlockedThreads != null) { |
| 105 | + builder.status(Status.DOWN); |
| 106 | + LOGGER.log(Level.TRACE, "Health check observed deadlocked threads: " + Arrays.toString(deadlockedThreads)); |
| 107 | + } |
102 | 108 | } catch (Throwable e) {
|
103 |
| - // ThreadBean does not work - probably in native image |
104 |
| - LOGGER.log(Level.TRACE, "Failed to find deadlocks in ThreadMXBean, ignoring this healthcheck", e); |
| 109 | + // ThreadBean does not work - probably in native image. Report ERROR, not DOWN, because we do not know that |
| 110 | + // there are deadlocks which DOWN should imply; we simply cannot find out. |
| 111 | + LOGGER.log(Level.TRACE, "Error invoking ThreadMXBean to find deadlocks; cannot complete this healthcheck", e); |
| 112 | + builder.status(Status.ERROR); |
105 | 113 | }
|
106 |
| - return HealthCheckResponse.builder() |
107 |
| - .status(noDeadLock ? Status.UP : Status.DOWN) |
108 |
| - .build(); |
| 114 | + return builder.build(); |
109 | 115 | }
|
110 | 116 | }
|
111 | 117 |
|
0 commit comments