Sleep and wait)

Source: Internet
Author: User
Sleep is used to sleep when a thread is called, and other threads cannot occupy the CPU. The OS considers that the thread is working and does not let out system resources. Wait enters the waiting pool to wait, other threads can occupy CPU resources. Generally, wait does not apply a time limit, because it is useless if the resources of the wait thread are not enough, wait for other threads to call the yyall method to wake up all the threads in the wait pool before entering the ready sequence to wait for the OS to allocate system resources. Sleep is a static method, who falls to bed, even if the sleep method of thread B is called in the main thread, the main thread is actually used to go to bed. To let thread B go to bedCodeSleepsleep (100 L) is used for CPU usage, the thread sleep for milliseconds, other processes can no longer use CPU resources, and wait (l) is used for waiting in the waiting pool, the CPU and other system resources are handed over for other processes. During these 100 milliseconds, this thread can be used by other threads notify. However, the difference is that other threads in the waiting pool will not be freed from being destroyed by notify, but this thread will automatically enter the ready queue after waiting for 100 milliseconds and wait for the system to allocate resources. In other words, sleep (100) will certainly run after 100 milliseconds, however, after 100 milliseconds, wait still waits for the OS to call and allocate resources. Therefore, the wait100 stop time is uncertain, but at least 100 milliseconds.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.