java – 极不寻常的情况 – 线程被锁定在它所持有的锁上?

我正在研究的这个
java程序似乎在启动时挂起,所以我尝试使用jconsole来调试问题.

事实证明它正在等待一个声明为 – 的方法的调用 –

synchronized void stopQuery()

但是这里是疯狂的部分,’同步’方法的锁已经被阻塞的线程所持有.
我在执行getThreadInfo()MXBean方法后附加了JConsole的屏幕截图.
请注意,lockOwnerId和threadId是一样的!这怎么可能呢?

《java – 极不寻常的情况 – 线程被锁定在它所持有的锁上?》

编辑:
  Link 到这种情况的堆栈痕迹之一.

请注意,在查看堆栈跟踪后,即使’org.eclipse.jdt.internal.ui.text.JavaReconciler’线程也试图锁定到同一个DiskIndex对象,但是如果你查看对象地址,你会看到看到它实际上是一个不同的DiskIndex对象.

编辑2:
 Another Link 我在转载此问题时获得了不同的堆栈跟踪.将两者进行比较以了解常见情况应该会有所帮助.

最佳答案 这看起来像是一个特别令人讨厌的僵局.没有更多信息,很难确定.这是我在没有代码的情况下看到的,但是:

当“Worker-3”持有对引用0x00002aace2276ad0的锁定时,“Text Viewer Hover Presenter”和“Worker-3”之间可能存在死锁(或至少争用)对象引用0x00002aace2276720.

第二个引用似乎是一堆被阻塞线程的原因(特别是“Worker-4”,“Worker-1”和“Worker-0”).

我的建议是检查ASTProvider.java第450行(请参阅前两个堆栈跟踪,其中似乎持有可疑对象锁,但似乎没有超过wait()).我还建议尝试将可执行文件锁定到单个核心(假设这是一个多核系统).

看起来值得测试的下一段代码是SelectionListenerWithASTManager.java第153行(其中引用0x00002aace2276ad0被锁定,导致Workers阻塞).

0x00002aace2276720的储物柜:

"Text Viewer Hover Presenter" daemon prio=10 tid=0x00002aad20166400 nid=0x51f4 in Object.wait() [0x000000004254c000..0x000000004254dd90]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    - waiting on <0x00002aace2276720> (a java.lang.Object)
    at java.lang.Object.wait(Object.java:485)
    at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.getAST(ASTProvider.java:450)
    - locked <0x00002aace2276720> (a java.lang.Object)
    at org.eclipse.jdt.ui.SharedASTProvider.getAST(SharedASTProvider.java:129)
    at org.eclipse.jdt.internal.ui.text.java.hover.NLSStringHover.getHoverInfo(NLSStringHover.java:87)
    at org.eclipse.jdt.internal.ui.text.java.hover.AbstractJavaEditorTextHover.getHoverInfo2(AbstractJavaEditorTextHover.java:86)
    at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo2(BestMatchHover.java:129)
    at org.eclipse.jdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy.getHoverInfo2(JavaEditorTextHoverProxy.java:82)
    at org.eclipse.jface.text.TextViewerHoverManager$4.run(TextViewerHoverManager.java:166)

"Worker-3" prio=10 tid=0x00002aad132c3800 nid=0x5166 in Object.wait() [0x0000000042249000..0x000000004224ab10]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    - waiting on <0x00002aace2276720> (a java.lang.Object)
    at java.lang.Object.wait(Object.java:485)
    at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.getAST(ASTProvider.java:450)
    - locked <0x00002aace2276720> (a java.lang.Object)
    at org.eclipse.jdt.ui.SharedASTProvider.getAST(SharedASTProvider.java:129)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:168)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$3.run(SelectionListenerWithASTManager.java:153)
    - locked <0x00002aace2276ad0> (a java.lang.Object)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

在0x00002aace2276ad0上被阻止

"Worker-4" prio=10 tid=0x00002aad132c4000 nid=0x5167 waiting for monitor entry [0x000000004234b000..0x000000004234bc90]
   java.lang.Thread.State: BLOCKED (on object monitor)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$3.run(SelectionListenerWithASTManager.java:153)
    - waiting to lock <0x00002aace2276ad0> (a java.lang.Object)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

"Worker-1" prio=10 tid=0x00002aad12835800 nid=0x5164 waiting for monitor entry [0x0000000041a42000..0x0000000041a42a10]
   java.lang.Thread.State: BLOCKED (on object monitor)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$3.run(SelectionListenerWithASTManager.java:153)
    - waiting to lock <0x00002aace2276ad0> (a java.lang.Object)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

"Worker-0" prio=10 tid=0x00002aad11a0ac00 nid=0x5146 waiting for monitor entry [0x0000000041941000..0x0000000041941d90]
   java.lang.Thread.State: BLOCKED (on object monitor)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$3.run(SelectionListenerWithASTManager.java:153)
    - waiting to lock <0x00002aace2276ad0> (a java.lang.Object)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
点赞