What’s a monitor referred to in concurrent programming in Java?
When I read that “every object has associated a monitor” what does it meaning?
Is it a special object?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A monitor is mechanism to control concurrent access to an object.
This allows you to do:
Thread 1:
Thread 2:
This prevents Threads 1 and 2 accessing the monitored (synchronized) section at the same time. One will start, and monitor will prevent the other from accessing the region before the first one finishes.
It’s not a special object. It’s synchronization mechanism placed at class hierarchy root:
java.lang.Object.There are also
waitandnotifymethods that will also use object’s monitor to communication among different threads.