notify() and notifyAll():

notify() and notifyAll():


notify() wakes up one thread and releases the lock. It is to send wake-up command to another one and only one thread that is in wait() status and is waiting for a notify command. After waking up, it will compete for the lock and as it is the only thread that was awake, it will get the lock and run. 


notifyAll() wakes up all waiting threads and releases the lock. It is to wake up other threads that are in wait() status and are waiting for a wake-up command (rather than the lock). After waking up, they will compete for the lock and the only one thread that gets the lock will run. Other threads are in ready state, not in wait() status (not waiting for wake-up command, but wait for lock). 

你可能感兴趣的:(java)