In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what is the difference between sleep and wait in Java. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
1. The sleep method is a static method of the Thread class
The wait method is a member method of the Object class
2. The sleep method suspends the execution of the current thread for a specified time and gives cpu to other threads, but its monitoring state is still maintained, and it will automatically resume the running state when the specified time is up. After calling the sleep method, the thread does not release the object lock
When the wait method is called, the thread abandons the object lock and enters the waiting lock pool waiting for the object. Only when the notify () method is called on this object does the thread enter the object lock pool and be ready.
3. The sleep method may throw an exception, so you need to handle the exception
The wait method does not need to be handled
4. The sleep method can be used anywhere
Wait methods can only be used in synchronization methods and synchronization code blocks
The life cycle graph of threads in Java is as follows:
This is the difference between sleep and wait in Java. I hope the above content can be helpful to everyone and learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.