Java监视器:阻塞代码段还是阻塞被代码段使用的资源?

huangapple 未分类评论55阅读模式
英文:

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?

huangapple
  • 本文由 发表于 2020年4月8日 16:22:28
  • 转载请务必保留本文链接:https://java.coder-hub.com/61096349.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定