Does Java blocked threads take up more CPU resources?

Oh Chin Boon picture Oh Chin Boon · May 5, 2011 · Viewed 8.9k times · Source

i would like to ask if Java will utilize more CPU resources when threads are blocked, i.e. waiting to lock a monitor which is currently being locked by another thread.

I am now looking at a thread dump whereby some threads are blocked as they are waiting to lock a monitor, and i am unsure if that is what may be accountable for the high CPU usage.

Thanks!

EDIT (6 May 2011) I forgot to mention if this behavior is relevant for Java SE 1.4.2.

Answer

Peter Lawrey picture Peter Lawrey · May 5, 2011

Threads consume resources such as memory. A blocking/unblocking thread incurs a once off cost. If a thread blocking/unblocks tens of thousands of times per second this can waste significant amounts of CPU.

However once a thread is blocked, it doesn't matter how long it is blocked for, there is no ongoing cost.