wait和sleep

sleep() belongs to the Thread class and will not release the lock, but only blocks the thread.
Wait() belongs to the Object class and will release the object lock. Only when other threads call notify() can the thread be awakened, wait( ) When using, the object lock must be acquired first, that is, it must be used in the synchronized-modified code block, and notify() is the same. If it is not used in the synchronized-modified code block, an IllegalMonitorStateException will be thrown at runtime.

Guess you like

Origin blog.csdn.net/weixin_45729934/article/details/105887563