문제

As per the javadoc notify Wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. A thread waits on an object's monitor by calling one of the wait methods.

I want to know how notify achieve this behavior. On many sites I read it sends a signal but What does signal means here?

Does notify sends a signal directly to first waiting thread or it sends a signal to thread scheduler?

도움이 되었습니까?

해결책

It does not send it to the first thread, but to any waiting thread (but only one thread).

You should read the javadoc more carefully.

Signal is also possibly a bad name for it, 'notify' is better. The actual implementation of the mechanism is transparent to the Java programmer, and the technical implementation should not be necessary for you to know.... unless you have an interest in Java internals, and then I suggest you inspect the OpenJDK source code.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top