Which monitor in Java?

Which monitor is mentioned in parallel programming in Java?

When I read that "every object is connected to a monitor," what does this mean?

Is this a special subject?

+104
java multithreading concurrency monitor
Jul 29 '10 at 12:14
source share
7 answers

A monitor is a mechanism for controlling concurrent access to an object.

This allows:

Theme 1:

public void a() { synchronized(someObject) { // do something (1) } } 

Theme 2:

 public void b() { synchronized(someObject) { // do something else (2) } } 

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.

+70
Jul 29 '10 at 12:17
source share

A monitor is an object that has both a lock and a wait . In Java, any Object can serve as a monitor.

For a detailed explanation of how monitors work in Java, I recommend reading the Monitoring Mechanics Concurrent Programming in Java (the previous link displays a preview in Google books, and this section is readable).

+22
Jul 29 '10 at 12:35 on
source share
  1. A monitor is a concept / mechanism that is not limited to the Java language;
  2. "In parallel programming, a monitor is an object or module designed to be used safely by more than one thread.";
  3. As every reader knows, every object in Java is a subclass of java.lang.Object. The java people made java.lang.Object so that it has features and characteristics that allow Java programmers to use any object as a monitor. For example, each object has a wait queue, a re-entry queue, and wait and notification methods that make it a monitor;
  4. Read about monitors here .
+7
Jan 17 '13 at
source share

The Java language and runtime support synchronization of threads using monitors.
A monitor is associated with a specific data item (condition variable) and functions as a lock on that data. When a thread holds a monitor for some data item, other threads are blocked and cannot check or modify data.

+4
Feb 19 '17 at 12:52 on
source share
+3
Jul 29 '10 at 12:20
source share

A monitor is a synchronization construct that allows threads to have both mutual exclusions and the ability to wait (block) for a certain condition to become true.

Monitors also have a mechanism to alert other threads that their condition is met. This is an entity that has both a lock and a wait set. In Java, any object can serve as a monitor.

In a Java virtual machine, every object and class is logically connected to a monitor. To realize the possibility of mutual exclusion of monitors, a lock (sometimes called a mutex) is associated with each object and class. In terms of operating systems, this is called a semaphore; a mutex is a binary semaphore.

For more information check the link

+2
Apr 26 '18 at 13:18
source share

http://journals.ecs.soton.ac.uk/java/tutorial/java/threads/monitors.html

the monitor communicates with an object or data element that is requested when a data element or object is entered, is a synchronization unit (critical section) and is freed upon exit.

+1
Feb 10 '18 at 7:40
source share



All Articles