The difference between wait() method and sleep() method in java multithreading

The difference between wait() method and sleep() method in java multithreading

1. The wait() method is a method of the object class, while sleep() is a method of the Thread class.
2. The wait() method must be used in the synchronized code block synchronized, and sleep() can be used
anywhere 3.wait() Method will release the lock, and sleep () will not release the lock
. 4. Use wait () method without throwing an exception, while using sleep () must throw InterruptedException exception

Guess you like

Origin blog.csdn.net/qq_41134324/article/details/109017699