2

I wrote a computationally heavy single threaded program, but when I executed it I was surprised to see that my quad core processor was at 95% utilization. I was expecting to see something close to 25% utilization (one core). I used the Process Explorer from sysinternals and was further surprised to see that the Java process had six threads with almost identical load distribution of about 16% total processor time.

Initially I was planning to parallelize my code, but now it seems that I won't gain any performance since the CPU is already at 95% load even with my non-parallel code.

It almost appears that Java is somehow automatically parallelizing my code, but everything on the net tells me that this cannot be true. Does anyone know what's going on?

Edit: I added some screenshots to hopefully answer some of the questions below:

System at idle - 1% load. I am uisng a quad core CPU with 8 logical cores. System at Idle

My non-parallel java program running. Note that all 4 cores are nearly maxed out: run

View of my non-parallel java program from SysInternals Process Explorer. Note the 8 threads with nearly identical load: procexp

Steve K
  • 83
  • 6
  • 1
    Most systems show usage as percentages of one cpu fully utilized. So at full utilization,your program would be at 400%. Not sure if that is your problem, but it is certainly possible you are just misinterpreting. – Others Dec 29 '15 at 05:51
  • 2
    Also use a dedicated java tool like jmc, jconsole or jstat to see whats going on. It could be the java heap is nearing OutOfMemory which causes the GarbageCollector to burn cpu. – Markus Kull Dec 29 '15 at 11:25
  • Hi Steve, are you getting 95% usage in all CPU cores? – Ravindra babu Dec 29 '15 at 12:59
  • 2
    Show us your code. Some of the new Java 8 streams can do automatic multi threading. –  Dec 29 '15 at 17:56

2 Answers2

1

On most systems I've used, usage percentages are actually what percent of one core's power the process is using. If your system is like that, you're simply misinterpreting the usage percentage. That is to say, java is using 95% of one CPU. Not sure if that is what is going on, but it would explain how an unparallelized program could display at 95%.

EDIT: Based on your edits, this does not appear to be the case. Perhaps like @a_horse_with_no_name suggests in the comments, your code is using a parallel stream or another automatically parallelized operation?

Others
  • 2,876
  • 2
  • 30
  • 52
  • No. The Windows task manager reports the CPU usage over all cores. With 8 cores, a single fully busy core will result in a CPU usage of 12% in the task manager. And the second screenshot also shows that all 8 cores are busy, not just one. –  Dec 29 '15 at 17:56
-4

Java is not parallelizing your code. Java is parallelizing itself. Remember Java runs in a virtual machine. That virtual machine is a program in itself.

William Rosenbloom
  • 2,506
  • 1
  • 14
  • 37