Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do the different (HotSpot) JVM thread types do?

I see there are six thread types implemented into the HotSpot JVM: VMThread, CGCThread, PGCThread, JavaThread, CompilerThread and WatcherThread. However I don't know which thread type is doing what exactly. Here is what I understood so far:

  • VMThread: run VM tasks like the garbage collector.
  • CGCThread: Concurrent garbage collector.
  • PGCThread: Parallel garbage collector (differences with CGC?).
  • JavaThread: Program's threads, I guess.
  • CompilerThread: A thread for the compiler?
  • WatcherThread: ?

Additional question: what about other JVMs?

like image 949
Florian Richoux Avatar asked Mar 06 '13 15:03

Florian Richoux


People also ask

What are JVM threads?

A Java thread is the execution path in a program. Everything that runs in Java is run in threads. Every application in the JVM world has threads, at least one, even if you don't call it explicitly. It all starts with the main method of your code, which is run in the main application thread.

How many threads JVM can handle?

Each JVM server can have a maximum of 256 threads to run Java applications. In a CICS region you can have a maximum of 2000 threads. If you have many JVM servers running in the CICS region (for example, more than seven), you cannot set the maximum value for every JVM server.

What is HotSpot in JVM?

HotSpot is a dynamic compiler. It combines the best features of a JIT compiler and an interpreter, combining the two in a single package. That two-in-one combination provides a number of important benefits for code performance, as you will shortly see.


3 Answers

You can find a brief explanation on the OpenJDK website:

The main kinds of VM threads are as follows:

  • VM thread: This singleton instance of VMThread is responsible for executing VM operations, which are discussed below
  • Periodic task thread: This singleton instance of WatcherThread simulates timer interrupts for executing periodic operations within the VM
  • GC threads: These threads, of different types, support parallel and concurrent garbage collection
  • Compiler threads: These threads perform runtime compilation of bytecode to native code
  • Signal dispatcher thread: This thread waits for process directed signals and dispatches them to a Java level signal handling method

You might want to read the whole Thread Management paragraph since it continues further explanations, e.g. what the VM thread is responsible for.

like image 81
box Avatar answered Oct 19 '22 16:10

box


Ok, thanks to comments, we have the beginning of an answer:

1) Since the garbage collector has a stop-the-world mecanism, there exist besides tunings two ways to reduce these pauses:

  • With parallel GCs running via PGCThreads such that, if n cores are available, then n threads can be run during pauses to shorten them.
  • With a concurrent GC, running via a CGCThread and finishing the job of the regular GC off pauses, concurrently with the main program thread.

2) The CompilerThread runs the Just-In-Time compiler.

3) The WatcherThread simulates timer interrupts every 50ms to run periodic operations in the VM.

like image 44
Florian Richoux Avatar answered Oct 19 '22 15:10

Florian Richoux


And I would add that there are 7 threads type in JVM! Don't miss os_thread

path: Defined in: /hotspot/src/share/vm/runtime/os.hpp

  enum ThreadType {
    vm_thread,
    cgc_thread,        // Concurrent GC thread
    pgc_thread,        // Parallel GC thread
    java_thread,       // Java, CodeCacheSweeper, JVMTIAgent and Service threads.
    compiler_thread,
    watcher_thread,
    os_thread
  };
like image 33
skytree Avatar answered Oct 19 '22 16:10

skytree