2

I am using the JKD8 and as I see with the following command by default the JVM use the parallel garbage collector. How can I observe if the garbage runs on a separate thread alongside the main program? Is there any parameter just like -XX:-PrintGCDetails option?

By the way, I am using Visual VM also can I observe it from there? For example in the ->"Threads" tab section because I can't find it.

java -XX:+PrintCommandLineFlags  -XX:-PrintGCDetails -version
-XX:InitialHeapSize=535233856 -XX:MaxHeapSize=8563741696 -XX:+PrintCommandLineFlags -XX:-PrintGCDetails -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
Holger
  • 285,553
  • 42
  • 434
  • 765
Mixalis Navridis
  • 181
  • 2
  • 15
  • You can try -XX:+PrintGCApplicationConcurrentTime – Evgeniy Dorofeev Dec 15 '18 at 15:01
  • @Evgeniy Dorofeev i am trying but i dont think i can see the separate thread with this way – Mixalis Navridis Dec 15 '18 at 15:09
  • You can also try -XX:+UseConcMarkSweepGC. This GC is supposed to run concurrently – Evgeniy Dorofeev Dec 15 '18 at 20:14
  • In some ways your question is based on a misunderstanding. The parallell collector is not a concurrent collector. When the collector is running all your application threads are stopped so your question does not make any sense. If you were using a concurrent collector (Concurrent MarkSweep collector or the G1 collector) then you can observe the GC threads doing work. – Erik Dec 17 '18 at 15:31
  • Possible duplicate of [java - Is garbage collector a daemon thread? - Stack Overflow](https://stackoverflow.com/questions/5218848/is-garbage-collector-a-daemon-thread) ? – user202729 Oct 05 '20 at 12:16

1 Answers1

2

Garbage collectors run in a separate thread. You can observe this in a thread dump:

...

"VM Thread" os_prio=0 tid=0x00007f4fec078000 nid=0x74c9 runnable 

"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00007f4fec01f800 nid=0x74c5 runnable 

"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00007f4fec021800 nid=0x74c6 runnable 

"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00007f4fec023000 nid=0x74c7 runnable 

"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x00007f4fec025000 nid=0x74c8 runnable 

...

You can generate a thread dump by sending SIGQUIT (3) to the process:

kill -SIGQUIT <pid>

See RedHat for this: https://access.redhat.com/solutions/18178

try-catch-finally
  • 7,436
  • 6
  • 46
  • 67