英文:
Java Monitors: Block code segment or block resources used by the code segment?
问题
我正在尝试在网上阅读关于Java监视器的资料,但无论在哪里,我都找到了非常通俗的定义。有人能否请说明 -
假设我们有一个同步块。我读到使用 'synchronized' 关键字的对象附带了监视器,以防止线程的并发访问。那么,
监视器是否只是不允许多个线程运行 'synchronized' 代码块?
还是
监视器是否知道正在被该方法使用的所有资源,并限制了对这些资源的使用?
英文:
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?
专注分享java语言的经验与见解,让所有开发者获益!
评论