shahrs87 commented on a change in pull request #3862:
URL: https://github.com/apache/hbase/pull/3862#discussion_r759148855
##########
File path: hbase-common/src/main/java/org/apache/hadoop/hbase/util/Threads.java
##########
@@ -197,4 +199,33 @@ public static void
setLoggingUncaughtExceptionHandler(Thread t) {
public static void printThreadInfo(PrintStream stream, String title) {
ReflectionUtils.printThreadInfo(stream, title);
}
+
+ /**
+ * Checks whether any non-daemon thread is running.
+ * @return true if there are non daemon threads running, otherwise false
+ */
+ public static boolean isNonDaemonThreadRunning() {
+ AtomicInteger nonDaemonThreadCount = new AtomicInteger();
+ Set<Thread> threads = Thread.getAllStackTraces().keySet();
+ threads.forEach(t -> {
+ // Exclude current thread
+ if (t.getId() != Thread.currentThread().getId() && !t.isDaemon()) {
+ nonDaemonThreadCount.getAndIncrement();
+ LOG.info("Non daemon thread {} is still alive", t.getName());
+ LOG.info(printStackTrace(t));
+ }
+ });
+ return nonDaemonThreadCount.get() > 0;
+ }
+
+ /*
+ Print stack trace of the passed thread
+ */
+ public static String printStackTrace(Thread t) {
+ StringBuilder sb = new StringBuilder();
+ for (StackTraceElement frame: t.getStackTrace()) {
+ sb.append("\n").append(" " + frame.toString());
Review comment:
Kept multiple spaces so as to make it look like stack trace.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]