I am troubleshooting a shutdown that is not as graceful as it should be, so I would like to get a list of running non-daemon threads in jvisualvm (or other) to hunt the culprit.
The simplest way to see the number of threads in Java is to use a graphical tool like Java VisualVM. Apart from the application threads, Java VisualVM also lists the GC or any other threads used by the application like JMX threads. Monitoring the number of threads is the most basic feature in Java VisualVM.
Daemon threads are low priority threads which always run in background and user threads are high priority threads which always run in foreground. User Thread or Non-Daemon are designed to do specific or complex task where as daemon threads are used to perform supporting tasks.
you can check thread as daemon or user by using "isDaemon()" method.
The threads which are always going to run in the background that provides supports to main or non-daemon threads, those background executing threads are considered as Daemon Threads. The Daemon Thread does not block the main thread from exiting and continues to run in the background.
jstack dumps all threads, there is a text that would tell if it is daemon or not
( jvisualvm produces same output in 'ThreadDump'- See this link for more useful documentation
"Reference Handler" daemon prio=10 tid=0x00a98400 nid=0x1ee8 in Object.wait() [0x00b6f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:485)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116)
- locked <0x19835fa0> (a java.lang.ref.Reference$Lock)
"VM Thread" prio=10 tid=0x00a95800 nid=0x264 runnable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With