The difference between sleep and wait, the problems often encountered during the interview, the lock we have to remember clearly:
Same point: Allows the thread to freeze (discard CPU execution)
Different points: 1,sleep must specify the time, wait can be specified between, or can not specify a time (easy error point);
2,sleep time, the thread is temporarily blocked and running, wait, if there is no time specified, must be awakened with notify or notifyall;
3,sleep not necessarily defined in synchronization, wait must be defined in synchronization;
4, if all is defined in the synchronization, the thread executes to sleep, does not release the lock, and the thread executes to wait, releasing the lock (emphasis).
The above 4th is the most important point, but also the most difficult to remember, but also the most easy to mix a little. to tell you about the skills to remember:
The methods and variables in Java are named for a certain rule of sleep, as the name implies just sleeping, my things to you, wake up how to do.
Wait is the meaning of waiting, that is, you wait for me, but if you hold this lock, it is me, I can not execute, can count me, so it's my turn, you have to give me the lock.
Similarities and differences between sleep and wait methods in Java