Java CPU utilization should be 100%… But not

I run a java program on my Core i7 laptop with 8 cores (4 physical, 4 HT) The program uses 8 parallel threads, so it should occupy all CPU When running with the '- server' parameter, it is always at 100% Without it, it is generally about 50% - 60% (always varying at a peak of 100% and decreasing at a level of 30%) This is what I find strange: when I run the program in debugging and wait for the CPU utilization to be particularly low (30%), then pause execution to see what eight threads are doing. None of them is blocked Moreover, there is little synchronization between them This is what I want to know:

>What is the difference between server and client VMS that prevent the CPU from reaching 100% on the client? > What makes a thread fully use the core without synchronization? (may link to 1)

Editor: it's an idea: the code allocates large arrays and leaves them to GC soon Does the thread sleep when calling 'new somethingbig()' and allocating the memory takes time? If the VM processes a thread and processes a process in the allocation, I think this can explain why they seem to pause randomly outside the synchronization block

Edit2: I'm pretty sure it's caused by GC If I give VM 1500mb instead of the default 500MB, the CPU will reach 100% again I don't think it will slow down in server mode because it uses more memory by default

Solution

If you want to monitor what the java thread is doing, you should not run the app in debug mode and suspend it

Instead, you should use kill - 3 < PID > to collect thread dumps at specific intervals when CPU usage drops

In relation to the second update, you should enable GC logging with a timestamp and correlate the slow / CPU utilization decline with the time of the young / full GC collection

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>