Home > Java > Javagetting Started > What is the difference between sleep() and wait() in Java?

What is the difference between sleep() and wait() in Java?

王林
Release: 2020-07-15 16:42:14
forward
2758 people have browsed it

What is the difference between sleep() and wait() in Java?

The difference is as follows:

sleep() is a method of the thread class (Thread), which is used to suspend the execution of the thread for a specified time and give the execution opportunity to other threads. However, the monitoring status is still maintained and will be automatically restored after the time is up. Calling the sleep() method does not release the object lock.

(Recommended related tutorials: java introductory tutorial)

wait() is a method of the Object class. Calling the wait() method on the object causes the thread to give up the object lock and enter Waiting for the waiting lock pool of this object. Only after the notify method (or notifyAll) is issued for this object, this thread will enter the object lock pool and prepare to obtain the object lock and enter the running state.

(Video tutorial recommendation: java video tutorial)

The above is the detailed content of What is the difference between sleep() and wait() in Java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template