The difference between sleep and wait

The basic difference

sleep is a Thread class method, wait method is defined in the class Object

sleep () method can be used anywhere

wait () method can only be used in a method of synchronized or synchronized block

The main essential difference

Thread.sleep will only make the CPU, the lock will not lead to changes in behavior

Object.wait not only let the CPU, will release the synchronization lock resources already occupied

Published 40 original articles · won praise 11 · views 3564

Guess you like

Origin blog.csdn.net/weixin_44584387/article/details/104700927