The difference between Java thread of sleep and wati

1.sleep from Thread class, Object class from the wait;

2.sleep method does not release the lock, and wait method releases the lock;

3.wait, notify, notifyAll only synchronization method or synchronized block, whereas sleep may be used at any place;

4.wait can specify the time may not specify the time, and sleep time must be specified;

5.sleep must catch the exception, and wait, notify and notifyAll do not need to catch the exception.

Published 21 original articles · won praise 10 · views 8094

Guess you like

Origin blog.csdn.net/weixin_44997483/article/details/102851913