What is a monitor?

What is a monitor?

- It can be considered as a building which contains a special room.

- The mechanism that Java uses to support synchronization is the monitor.

It supports two kind of thread synchronization.

1. Mutual exclusion
2. Cooperation

1. Mutual exclusion:
- Supported in JVM via object block.
- It enables multiple threads to independently work on shared data without interfering with each other.

2. Cooperation:
- Supported in JVM via wait() and notify() methods of class objects.
- It enables threads to work together towards a common goal.
Use of synchronization keyword
Use of synchronization keyword - A method, declared as synchronized, first attains a lock over an object before beginning an execution...
How do we allow one thread to wait while other to finish?
How do we allow one thread to wait while other to finish? - The wait method, notify method, and notifyAll method provide an efficient transfer of control from one thread to another...
Purpose of yield method
Purpose of yield method - The yield method causes the currently executing thread object to temporarily pause...
Post your comment