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