Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

jvm

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();
            b.print();
        }
    }
}

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

Opening the jvisualvm 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

Note: 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

like image 915
Shady Atef Avatar asked Sep 01 '26 23:09

Shady Atef


2 Answers

  • 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.

like image 69
apangin Avatar answered Sep 05 '26 03:09

apangin


The Reference Handler is for handling References (SoftReference, WeakReference, PhantomReference and their subclasses), the Finalizer threads calls the finalize() method of finalizable objects.

The JMX and RMI threads are what allows you to watch the running JVM.

I don't know what the other two threads do.

like image 28
Thomas Kläger Avatar answered Sep 05 '26 02:09

Thomas Kläger