Does Java keep a count of the number of notifys for a given object? That is, if notify() is called three times on on object A, then will three waits at a later time proceed immediately? Also, if there are three waits on A then at a later point three notifies on A will resume all of three of them?
- No, Java does not store notifys. That means that if notify is called on a synchronization object with no objects waiting, it is simply discarded.
- The waiting objects however are kept on a pool, so if we have three objects there and three notifys occur, each (previously) waiting object can proceed, as soon as it recaptures the lock on the synchronization object (recall that both wait and notify must be called with lock possession).