[Java] The difference between sleep and wait

Source: Internet
Author: User

For the Sleep () method, we first need to know that the method belongs to the thread class. The wait () method is part of the object class.

The sleep () method causes the program to pause execution for the specified time, giving up the CPU to that other thread, but his monitoring state remains, and when the specified time is up, it will automatically resume its running state.

During the call to the sleep () method, the thread does not release the object lock.

When the Wait () method is called, the thread discards the object lock, enters the waiting lock pool waiting for the object, and the thread only enters the object lock pool when the Notify () method is called for this object.

Gets the object lock into the running state.

[1] http://www.cnblogs.com/hongten/p/hongten_java_sleep_wait.html

[Java] The difference between sleep and wait

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.