shahrs87 commented on a change in pull request #3862:
URL: https://github.com/apache/hbase/pull/3862#discussion_r757671579
##########
File path: hbase-common/src/main/java/org/apache/hadoop/hbase/util/Threads.java
##########
@@ -197,4 +199,34 @@ 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));
Review comment:
This is the sample stack trace after deploying it to internal cluster
```
2021-11-26 19:21:16,747 INFO [main] util.Threads - Non daemon thread
main.named-queue-events-pool-pool1-t1 is still alive
2021-11-26 19:21:16,748 INFO [main] util.Threads -
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2044)
com.lmax.disruptor.BlockingWaitStrategy.waitFor(BlockingWaitStrategy.java:45)
com.lmax.disruptor.ProcessingSequenceBarrier.waitFor(ProcessingSequenceBarrier.java:56)
com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:124)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
```
There is no easy method to print stack trace given a thread handle.
`Thread#dumpStack` dumps stack of current thread but we don't need that.
Cc @virajjasani @Apache9
--
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]