GD_Java GD_Java - 2 years ago 56
Java Question

How notify method works

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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download