Reputation: 91
I use jstack to output the thread info. And there is a thread: "VM Thread" prio=10 tid=0x0878b400 nid=0x760a runnable
What is this thread used to do? It takes 50% CPU usage and most of CPU time
Upvotes: 9
Views: 8987
Reputation: 3913
The VM thread is an internal JVM thread and you would not see that in JConsole but on an threaddump
(use jstack
) or OS utility such as top (top -H .... )
or ps
.
This VM Thread if it is consistently taking a huge amount of CPU could be a precursor to an OOM Heap error.
This usually can happen when there are "stop the world" GC happening. It could be due to a memory leak or as innocuous as running on a single CPU and / or a Serial GC Collector and / or loading the heap with objects that cannot be GC'ed since they are active on the stack and / or sizing the heap too low compared to workflow and implied concurrency etc..
Example below.
It is simple to replicate:
try running on a constrained heap (say 256m), limit to a single cpu (using docker or an OS specific utility), specify a larger number of worker threads that read images into memory and you would see that with this command (on linux):
top -n 1 -H -p {pid}
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
10 root 20 0 3335964 395380 28380 R 60.0 19.4 0:34.71 VM Thread
Upvotes: 2
Reputation: 1336
The VM thread is defined here as:
This thread waits for operations to appear that require the JVM to reach a safe-point. The reason these operations have to happen on a separate thread is because they all require the JVM to be at a safe point where modifications to the heap can not occur. The type of operations performed by this thread are "stop-the-world" garbage collections, thread stack dumps, thread suspension and biased locking revocation.
There's also some information provided in a de-duplicated SO answer here.
Upvotes: 11
Reputation: 533472
How do you know that this thread is taking 50% usage? Being runnable doesn't mean its consuming cpu.
AFAIK this is used for internal java operation, possibly involved in GC.
Which version of java are you using? I would check you have an up to date version of Java and see if this still happens.
I would suggest you memory profile your application to see how much objects you are creating and see if you can reduce your object count to reduce any GC work load.
Upvotes: 0
Reputation: 12785
I think it is the Garbage Collection thread. It does Garbage Collection.
Upvotes: 1