blueprint.sdk.util.debug.DeadlockDetector Maven / Gradle / Ivy
/*
License:
blueprint-sdk is licensed under the terms of Eclipse Public License(EPL) v1.0
(http://www.eclipse.org/legal/epl-v10.html)
Distribution:
Maven Central - https://search.maven.org/artifact/io.github.lempel/blueprint-sdk
MVN Repository - https://mvnrepository.com/artifact/io.github.lempel/blueprint-sdk
*/
package blueprint.sdk.util.debug;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import blueprint.sdk.util.jvm.shutdown.TerminatableThread;
/**
* Periodically checks MXBean for deadlock.
*
* @author [email protected]
* @since 2013. 11. 6.
*/
@SuppressWarnings("WeakerAccess")
public class DeadlockDetector extends TerminatableThread {
private static final Logger L = LoggerFactory.getLogger(DeadlockDetector.class);
public DeadlockDetector() {
super();
setDaemon(true);
}
@Override
public void run() {
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
while (running) {
// Returns null if no threads are deadlocked.
long[] threadIds = bean.findDeadlockedThreads();
if (threadIds != null) {
ThreadInfo[] infos = bean.getThreadInfo(threadIds);
for (ThreadInfo info : infos) {
StackTraceElement[] stack = info.getStackTrace();
for (StackTraceElement stackTraceElement : stack) {
L.warn(stackTraceElement.toString());
}
}
}
try {
Thread.sleep(30000);
} catch (InterruptedException ignore) {
}
}
terminated = true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy