Java thread synchronization and semaphores

Source: Internet
Author: User

 

The relationship between the thread lock of Java and the entry set and wait set, or the figure contains the mysteries of the Java thread. If you do not understand this figure or have never seen it, it only indicates that the Java thread lock is completely unknown.

(1) All threads that are expected to get the Lock will enter the entry set area of the Object Lock when the Lock has been owned by other threads.

(2) When all the locks have been obtained but other necessary conditions are not met and wait is required, the thread enters the wait set area of the Object Lock.

(3) When the Thread in the wait set area receives the Notify/notifyAll notification, a random Thread (Notify) or all threads (NotifyALL) the wait set area of the Object Lock enters the entry set.

(4) When the thread with the Lock is released, the thread in the entryset area of the Object Lock will seize the Lock, however, only one Thread can obtain the lock, while other threads still wait in the entry set for the next time to seize the lock and then execute the lock.

 

Refer:

1. http://lass.cs.umass.edu /~ Shenoy/courses/fall01/labs/talab2.html

2. http://stackoverflow.com/questions/289434/how-to-make-a-java-thread-wait-for-another-threads-output

3. http://java.sun.com/docs/books/jls/second_edition/html/memory.doc.html

4. https://prof.hti.bfh.ch/myf1/opsys1/CourseNotes/javasem.pdf

 

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.