Thread synchronization of Java virtual machines

Source: Internet
Author: User

Thread synchronization 

One of the advantages of the Java programming language is that it provides multi-threaded support at the language level. Multithreading support is primarily built around synchronization : Coordinate data access across multiple threads. The mechanism that Java uses to implement synchronization is what we call Monitor. This article describes how monitor and how the Java Virtual machine uses monitor -the data locking and unlocks supported by the instruction set.

Monitor

Java Monitor supports two types of thread synchronization, mutual exclusion and collaboration, mutual exclusion: A Java Virtual machine implements mutual exclusion through an object lock, allowing multiple threads to work without interfering with each other on the shared data; collaboration: A Java Virtual machine passes the wait () of the object class, Notify () method to implement multi-threaded work together.

A monitor thinks of a house with a special room in it that can only be occupied by one thread at a time. This room generally contains the following data, from the thread into the room to leave the room, the data inside the exclusive, only this thread can access. Into this House we call it into the monitor (the Entering, the monitor), into the room we call the acquiring, which takes possession of this room we call the monitor (owning, Leaving the room, we call the release monitor (releasing the monitor), leaving the entire house, which we call the Exit monitor (exiting the monitors).

In addition to data-related, monitor is also relevant to the code, which is called the Monitoring area (monitor regions). The monitor area is a set of inseparable execution actions for the monitor. In other words, a thread will not be able to execute the monitor's monitor area from the time it starts executing the monitor to the completion of the execution. The monitor ensures that only one thread executes this monitoring area at the same time.

Thread synchronization of Java virtual machines

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.