The difference between Android notify () Notifyall ()

Source: Internet
Author: User

both notify () and Notifyall () are methods that object objects are used to inform the thread that is waiting for the object.

void Notify (): Wakes up a thread that is waiting for the object.
void Notifyall (): Wakes all threads that are waiting on the object.

The biggest difference between the two is:

Notifyall causes all threads that originally wait on the object to be notify to exit the wait state, becoming a lock on the object, and once the object is unlocked, they compete.
Notify he just chooses a wait-state thread to notify, and it gets the lock on the object, but does not disturb other threads that are also waiting to be notify by the object, releasing the lock on the object when the first thread finishes running, and if the object does not use the Notify statement again, Even if the object is idle, the other waiting-state waits for the thread to remain in the wait state until it emits a notify or notifyall, and waits for a notify or notifyall instead of a lock, because the object is not notified.

The difference between Android notify () Notifyall ()

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.