Does thread.yield() lose the lock on object if called inside a synchronized method?

前端 未结 3 473
感情败类
感情败类 2020-12-15 11:19

I understand that Thread.currentThread().yield() is a notification to thread scheduler that it may assign cpu cycle to some other thread of same priority if any

3条回答
  •  执念已碎
    2020-12-15 11:45

    Only wait methods of the Object class release the intrinsic lock of the current instance (the thread may have other locks acquired, they don't get released). Yield, sleep, join do not bother about locks. However, join is a little more special, you are guaranteed to see all the changes made by the thread you're waiting for to finish.

提交回复
热议问题