0

My Java web application is slowing down over a period of time. When I check the resource utilization, I find that the java.exe is consuming more CPU.

When I take the thread dump to analyse, the following thread is highlighted as the top consumer.

VM Thread" prio=10 tid=0x000000001ba2f000 nid=0x3504 runnable

What is the purpose of this thread? How and why is it slowing down my application and how can I arrest this?

Anjan Baradwaj
  • 1,219
  • 5
  • 27
  • 54

1 Answers1

2

This is a system thread; see What does java "VM thread" do? If it is consuming a lot of time, it probably means that your JVM is doing a lot of "stop the world" garbage collecting.

If your JVM is spending a lot of time garbage collecting, that typically means that your heap is close to full and you are getting close to the point where you will get an OutOfMemoryError failure.

There are two possible causes for this kind of thing:

  • Your heap is too small for the computation you are trying to perform.
  • Your application has a memory leak.

In the former case, you can either increase the heap size, or reduce the problem size, or modify the application to use memory more efficiently. Note that if you keep increasing the heap size, you will eventually have to worry if you have enough address space and physical RAM in your machine.

In the latter case, you need to find and fix the bug or bugs on your application that are causing the memory leak. There are lots of articles on finding and fixing Java memory leaks.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • also : G1GC (or shenandoah, even) will postpone his issue quite significantly into the future, maybe even well beyond the lifespan of his webapp ... **if** that is something which is desirable for him *(i made the experience that beginners usually tend to work around problems rather than fixing them so this might be a solution worth mentioning for him)* – specializt Apr 30 '19 at 06:41
  • Note for other readers: the G1GC here is [Garbage First Garbage Collector](https://www.oracle.com/technetwork/articles/java/g1gc-1984535.html), a means to tune the VM so that gc happens efficiently. However, it has to be noted that it might only take away the symptom, not solving the actual problem. If there is a memory leak or not having enough heap space at your disposal (inefficient memory use / bad design / ... ) you have to tackle it down in your code. – KarelG Apr 30 '19 at 06:52
  • If the problem is a memory leak, then GC tuning is not a good solution. It is a band-aid ... – Stephen C Apr 30 '19 at 09:19