Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JVM Core Threads

On starting a JVM instance on my machine, with a simple class running infinite sleep in main(), I see four key threads (apart from the main thread) in the JVM:

  1. Attach Listener
  2. Reference Handler
  3. Finalizer
  4. Signal Dispatcher
  5. DestroyJavaVM

I am curious to understand purpose of each of these core JVM threads. From a quick internet search, I found the following details on these threads:

  1. Attach Listener: Dynamic attach has an attach listener thread in the target JVM. This is a thread that is started when the first attach request occurs.
  2. Signal Dispatcher: When the OS raises a signal to the JVM, the signal dispatcher thread will pass the signal to the appropriate handler.
  3. Reference Handler: High-priority thread to enqueue pending References. The GC creates a simple linked list of references which need to be processed and this thread quickly adds them to a proper queue and notifies ReferenceQueue listeners.
  4. Finalizer: The Finalizer thread calls finalizer methods.
  5. DestroyJavaVM: This thread unloads the Java VM on program exit. Most of the time it should be waiting.

I'd like to know further details (or correction in understanding) on these threads and reference documentation (if known).

like image 928
drop.in.ocean Avatar asked Oct 17 '13 12:10

drop.in.ocean


1 Answers

You've pretty much got that right, the only further clarification I'd add is with the attach listener thread (which is responsible for dynamic attach.) This isn't something that's usually used, but essentially allows another process to inject a thread inside the running JVM to query certain details about how the VM is running. It's only used in practice (as far as I've seen) between two Java VM's, such as when debugging or profiling (or in the case of some IDEs that display some other information about user code as it's running.)

Note that all of these threads are heavily implementation dependent and aren't necessarily on other VM's (or even different versions of the same VM, or the same VM with different options.) The JVM may start up as many or as few core threads as it likes on launch, the number and type of those (aside from the main thread) are not under user control.

like image 165
Michael Berry Avatar answered Sep 24 '22 19:09

Michael Berry