Wait and notify in Java Multi-threading

Source: Internet
Author: User
Tags thread class

(1) Wait:

1. Wait is a method of the object class, and sleep is a method of the thread class.

2. The thread that is currently accessing my object, wait.

3. Current this thread, locked in the current object of this thread stopped.

4. Wait only after locking; If it is not synchronized, call wait directly and make an error immediately.

(2) The problem of the lock:

  1. Is it not the lock that owns this object? Once wait, immediately died, this object's lock no longer belongs to me all, only then woke up, I will find this lock again, bring it back.

(3) The difference between wait and sleep:

  1. Wait time, the lock will not give me all.

2. Sleep, sleep also hold the lock, it is more greedy.

Wait and notify in Java Multi-threading

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.