What is a monitor?- A monitor works as a lock on the data item.
- When a thread holds the monitor for some data item, other threads are locked out and cannot inspect or modify the data.
- A unique monitor is associated with every object. These objects must be synchronized.
- They are also used to coordinate threads to make sure that they don’t trip over each other accessing the same data.
- It is a class which is used in the context of concurrency.
It supports two kinds of thread synchronization:
1. Mutual exclusion 2. Cooperation
1. Mutual exclusion:
- It is supported on the JVM via object locks. - It enables multiple threads to independently work with shared data.
2. Cooperation:
- It is supported on the JVM via the wait() and notify() methods of class object. - It enables threads to work together towards a common goal.
|