多个锁在同一对象上的用途是什么?

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

ReEntrantLcoks-What is the use of having multiple locks on the same object

问题

在浏览了 ReentrantLock 的优势之一时,

> 使用 ReentrantLock,线程可以多次在同一对象上获得锁。

我遇到了这个回答,其中指出 get(index) 方法会发生死锁。如果在 get(index) 上没有使用任何同步,有人可以解释一下在这一点上如何发生死锁吗?

相同对象上使用多个锁的用例

英文:

While going through the advantages of ReEntrantLock one of them is:

> With ReentrantLock, a thread can acquire lock on the same object more
> than once.

I came across this answer which states that there would be a deadlock in the get(index). Can someone please explain how can a deadlock occur at that point, if we are not using any synchronization on get(index)?

UseCase of multiple locks on same object

huangapple
  • 本文由 发表于 2020年5月3日 18:16:34
  • 转载请务必保留本文链接:https://java.coder-hub.com/61572811.html
匿名

发表评论

匿名网友

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

确定