Reputation: 131
I was profiling my application using JProfiler and as result, in "CPU Views" section it shows that more than 40% of CPU time is spent on Object.wait()
. However as far as I know on Object.wait()
CPU is not given to the waiting thread.
Could somebody help understand what's going on and why the profiler shows that this much of CPU is spent on Object.wait()
?
Upvotes: 11
Views: 4124
Reputation: 48060
JProfiler distinguishes between various thread states. The displayed time for the wait method depends on the thread state selector in the upper right corner of the CPU views. Please see http://blog.ej-technologies.com/2009/07/thread-states-in-cpu-profiling-views.html for more information.
Upvotes: 0
Reputation: 40679
40% of what? Suppose you profile the following code:
for (i = 0; i < 1000; i++){
sleep(1);
}
If you look only at CPU time (not wall-clock time), nearly all of it will be in sleep
.
Why? Because it's using very little CPU time at all, but of the CPU time it is using, nealy all of it is spent entering and leaving sleep
.
Of course, if you do look at wall-clock time, even more of it will be in sleep
.
Same goes for any blocking call, like wait
.
Upvotes: 5
Reputation: 62045
The profiler does not know that the CPU is idle while in wait()
. All that the profiler knows is that wait()
was entered, and several milliseconds later it returned. So, if those milliseconds tend to take up 40% of your execution time, there you have it.
Upvotes: 7