the difference between notify and notifyAll
1 notify is wake the thread which invoke the wait-method
2 notifyAll is wake all the threads waiting for the lock released
3 why can form the thread invoking the wait-method and threads waiting for the lock released?
we know, if a synchronized method is invoked, all the other synchronized methods belong to the object can not be invoked, so the invoking threads must be blocked, and waiting the method can be invoke, so they all waite for the lock released in the list of waiting queue.
a synchronized class is the same;
when the notify method occurs, the waiting one who invoked wait() be wake;
when the notifyAll method occurs, the waiting queue choose the most prior one to wake, can be the one invoking wait(), also can be the ones waiting the lock released;
1 notify is wake the thread which invoke the wait-method
2 notifyAll is wake all the threads waiting for the lock released
3 why can form the thread invoking the wait-method and threads waiting for the lock released?
we know, if a synchronized method is invoked, all the other synchronized methods belong to the object can not be invoked, so the invoking threads must be blocked, and waiting the method can be invoke, so they all waite for the lock released in the list of waiting queue.
a synchronized class is the same;
when the notify method occurs, the waiting one who invoked wait() be wake;
when the notifyAll method occurs, the waiting queue choose the most prior one to wake, can be the one invoking wait(), also can be the ones waiting the lock released;