Java – if called in the synchronization method, thread. Will yield() lose the lock of the object?

I understand thread currentThread(). Yield () is a notification thread scheduler that can assign CPU loops to other threads of the same priority, if any

I can't find it in Javadoc and forums[ http://www.coderanch.com/t/226223/java-programmer-SCJP/certification/does-sleep-yield-release-lock ]There are 50-50 answers

I think yield () (let's say thread1) should release the lock, because if a thread with the same priority (let's say thread2) wants to run on the same object, it may have a chance when the thread scheduler finally assigns the thread to thread2

Solution

Thread. Yield() is not like object wait(). It simply relinquishes control to allow threads to switch It will have no effect on the concurrency of your program

There is no guarantee that the scheduler will run after the yield

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>