A monitor is a mechanism for controlling concurrent access to an object.
This allows:
Theme 1:
public void a() { synchronized(someObject) {
Theme 2:
public void b() { synchronized(someObject) {
This prevents threads 1 and 2 from simultaneously accessing the monitored (synchronized) section. One will start, and the monitor will not allow another access to the region until the first is completed.
This is not a special object. The synchronization mechanism is located at the root of the class hierarchy: java.lang.Object .
There are also wait and notify methods that will also use the object monitor to communicate between different threads.
Pablo Santa Cruz Jul 29 '10 at 12:17 2010-07-29 12:17
source share