Diga Diga - 6 months ago 18
Java Question

Java Single Thread CPU Use and Multithread CPU Use

I've been writing an application for matrix multiplication.

I've got it done and watched resource monitor for comparison.

First of all


  1. 3000x3000 matrixes multiplied.

  2. Single threaded was slower than multi threaded

  3. When I check Windows resource monitor, I see that multithreading app has more threads than single threaded. I checked "javaw.exe" and even if I write single threaded app, it has more threads than one. That's not about me. That's about "javaw.exe" itself. But long story short, javaw with single thread showed - for example - 16 threads. Multi threaded showed - for example - 24.

  4. While multi threaded app working, CPU use was almost 100%. Most of use belong to "javaw.exe". But in single threaded app, the use was around 30-35%



I've a i5 CPU. Dual core. 4 cores logical.

When I check Windows resource monitor, for multi thread app, CPU 0-1-2-3 use was almost 100%, again.

But in single thread app, CPU 0-1-2-3 was still using. Around same percentages, but not even close to 100%.

Here goes my question. When I was executing single threaded app, who was using the other cores? Of course any other process can use them. Or even "javaw.exe" itself (I told myself, it was multithreaded). But is there any possibility that JVM executes my single threaded process as multi threaded?

Answer

But is there any possibility that JVM executes my single threaded process as multi threaded?

No. The JVM will have multiple threads but it won't and can't just decide to multithread your program unless you create the threads yourself (or use some other multithreading mechanism like Executor).

Comments