I see in JConsole that I still have 2 non daemon threads but I can't find out which exactly (total number of thread is beyond 30).
Visual VM doesn't provide such information.
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.
boolean isDaemon(): This method is used to check that the current thread is a daemon. It returns true if the thread is Daemon. Else, it returns false.
Why JVM terminates the daemon thread if there is no user thread? The sole purpose of the daemon thread is that it provides services to user thread for background supporting task. If there is no user thread, why should JVM keep running this thread. That is why JVM terminates the daemon thread if there is no user thread.
Java offers two types of threads: user threads and daemon threads. User threads are high-priority threads. The JVM will wait for any user thread to complete its task before terminating it. On the other hand, daemon threads are low-priority threads whose only role is to provide services to user threads.
Run:
$ jstack PID | grep tid= | grep -v daemon
This will dump all the thread of a given Java PID, filter lines with thread names and filter out non-daemon ones.
Remove -v
to print daemon threads only.
Take a thread dump in VisualVM. Daemon threads have the word 'daemon
' next to the thread name.
"Default RequestProcessor" daemon prio=1 tid=101e58000 nid=0x124d86000 runnable [124d85000]
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