1

I was trying to read up on Java Monitors online, but everywhere I'm finding a very layman's definition. Can someone pls clarify ->

Say we have a syncronized block. I read that objects with the 'synchronized' keyword have monitors attached to them, to disallow concurrent access from threads. So,

Do monitors simply not allow the 'synchronized' block of code to be run by multiple threads?

OR

Do monitors know which all resources are being used by that method, and restrict the use of those resources?

Dhruv Chadha
  • 1,161
  • 2
  • 11
  • 33
  • Have you checked this https://stackoverflow.com/questions/3362303/whats-a-monitor-in-java? `This prevents Threads 1 and 2 accessing the monitored (synchronized) section at the same time.` The first of your "OR" is correct – Dmitrii Bocharov Apr 08 '20 at 08:30
  • Ya I saw that. I'm concerned whether there is some missing information in that answer. Do you think 1st choice is correct based solely on that answer? I read that answer and suddenly the 2nd choice struck me as a doubt... – Dhruv Chadha Apr 08 '20 at 08:35
  • but if some other code uses the same resource, wont that resource be blocked? if yes, is it the monitor's doing? if no, isnt that bad? – Dhruv Chadha Apr 08 '20 at 13:50

0 Answers0