Shady Atef Shady Atef - 1 year ago 71
Java Question

What are these JVM daemon threads created in simple java code?

I have so simple java app, It simply creates an object, calls a function on it all these inside an infinite loop

public class h {
public static void main( String[] args) {
while(true) {
B b = new B();

class B {
public void print() {
System.out.println("Hello I'am class B");

Opening the
I see 10 threads created by the JVM, only one active which is the main thread and 9 daemons.

What is the usage of these 9 threads ?

And is anyone of them related to Garabage collection in any manner ?
enter image description here

output of
java -version

java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)

OS : Arch Linux 4.8.6-1

Answer Source
  • Reference Handler thread is responsible for adding Weak, Soft and Phantom references discovered by Garbage Collector into their registered ReferenceQueues.
  • Finalizer thread runs finalize method of the objects ready to be finalized.
  • Signal Dispatcher waits for specific OS signals and handles them. In particular, it makes thread dump on SIGQUIT, and also initiates VM shutdown process on SIGTERM, SIGINT, SIGHUP.
  • Attach Listener thread supports Dynamic Attach mechanism. It listens for incoming Dynamic Attach connections and executes VM commands. For example, it is used by jstack, jmap and jcmd utilities.
  • RMI TCP Accept thread obviously accepts new RMI connections.
  • RMI TCP Connection threads serve the established RMI connections.
  • RMI Scheduler runs RMI background tasks like DGC.
  • JMX server connection timeout thread terminates JMX connetion when needed.

Reference Handler, Finalizer and partly RMI Scheduler are related to GC.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download