Does the Java: thread give up cpu when it is blocked by synchronized, reentrantlock, etc.?

see that there is a saying that the thread usually gives up cpu

Thread.currentThread().yield();
IO
Sleep,  wait

so does the thread give up cpu when it is blocked by synchronized, reentrantlock, etc.?

Nov.15,2021

what to do on a single core without cpu,? isn't there a deadlock?


not necessarily. Jvm uses some lock optimization strategies, such as spin locks, so cpu will not be abandoned.
if the spin time is up and the lock is still not acquired, the real cpu blocking will be abandoned.

Menu