Waiting, collection, and notification

Source: Internet
Author: User

Wait

Wait for the Operation to occur after the wait () or time form wait (long millisecs) and wait (long millisecs, int nanosecs) are called. A wait (long millisecs) call with parameter 0 or a call with two 0 parameters of wait (long millisecs, int nanosecs) is equivalent to a call with wait.

If the thread does not return interruptedexception when an interrupt exception is thrown, the thread returns normally from wait.

Notification

The notification operation occurs after calling notify () or notifyall. Make thread t any thread that executes the method on object m, and make n the number of lock operations on object m by thread t, and N is not matched by the unlock operation, the following situations may occur:

  • If n = 0, illegalmonitorstateexception is thrown. The scenario is: thread t has no lock occupying the target object m;
  • If n> 0, and this is a notify () operation, if the object mWaitIf the set is not empty, the object m is waiting for a member thread U in the set to be selected and deleted from the waiting set, so that the thread u can continue in the waiting operation. Note that the U Lock operation can be successful only after T completely unlocks the object m monitor;
  • If n> 0, and this is a policyall () operation, then all waiting threads wait for the collection to be deleted.

Interrupted

An interrupted operation occurs after the call method thread. Interrupt () or new threadgroup (). Interrupt.

Interaction of waiting, notification, and interruption

 

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.