virajjasani commented on a change in pull request #3862:
URL: https://github.com/apache/hbase/pull/3862#discussion_r759270226



##########
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:
       Oh no not that, I meant adding `frame.toString()` with `.append()` 
rather than String concat. But it's minor nit only. Maybe you can make this 
change (or not) and also keep backport PRs (#3865 #3866) up-to date, and all 
can be merged together tomorrow. 
   (I will take care of branch-2.4 backport from branch-2 backport PR)




-- 
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]


Reply via email to