You also have to remove the sleep from the second test, which would
reduce the elapsed time accordingly.
From my understanding the "sleep" is just to simulate the threads "doing
other stuff" such as waiting for a DB/disk/etc. to respond,
No, if you review the code in the Task class, you'll see that sleep() is
run only once at the entry point of the call() method - just prior to
executing the 20K loop. So the run / wait states illustrated in the
profiler evidently only account for the string concatenation performed in
the loop - which is very tight CPU bound code.
The sleep period evidently just enables all 50 Task thread instances to be
loaded so that they may run concurrently.
The author stated that he was using JProfiler, which is a JVM profiler,
which may not measure the actual CPU run / wait states, but rather measures
what the JVM is allowing to run, when.
The tests referenced in the article indicate that support provided by
java.util.concurrent
can "force" a JVM to utilize multiple cores - but at a HORRIBLE cost.
A Java nut might say, "Look ma, I can take a multi-threaded CPU bound
workload that would normally use 60% of one core for 15 seconds and force
it to use 100% of 8 cores for 11 seconds, and accomplish the same thing."
Then the nut would have to duck as his mother threw the rolling pin at his
head.
If this is the best Java can do, then I would have to agree with Ronald
Luijten that Java doesn't support multi-cores "at all".
Nathan.
As an Amazon Associate we earn from qualifying purchases.