A very unusual situation. Is the thread locked on the lock that it holds?

This java program I'm working on seems to freeze at startup, so I tried using jconsole to debug the problem. As it turned out, he is waiting for a method call that is declared as

synchronized void stopQuery() 

But here's the crazy part, the lock for the "synchronized" method is already held by the thread that is blocked for it. I attached a screenshot from JConsole after executing the getThreadInfo () MXBean method.

Please note that lockOwnerId and threadId are the same! How is this possible?

alt text http://s4.tinypic.com/1zwnia1.png

Edit:
Link to one of the stack traces of this situation. Please note that after viewing stacktrace, it might seem that even the stream 'org.eclipse.jdt.internal.ui.text.JavaReconciler' is trying to lock the same DiskIndex object, but if you look at the address of the object, you will see that it is actually another DiskIndex object.

Edit 2:
Another link to another stack obtained by playing this problem. It would be helpful to compare the two to see what is common.

+4
source share
5 answers

This looks like a particularly unpleasant dead end. It is hard to say for sure without additional information. Here is what I see without a code in front of me:

A possible deadlock is (or at least against competition) A reference to the object 0x00002aace2276720 between the "Text Viewer Hover Presenter" and "Worker-3", and "Work-3" holds the lock at the link 0x00002aace2276ad0.

This second link is apparently the cause of a whole bunch of blocked threads (in particular, Work-4, Work-1, and Work-0).

My suggestion was to check the ASTProvider.java 450 line (see the stack trace for the first two, where the suspicious object's lock seems to hold, but then doesn't seem to pass by wait ()). I also suggest trying to run an executable file locked for one core (assuming it is a multi-core system).

The next piece of code that looks like it's worth checking out will be SelectionListenerWithASTManager.java line 153 (where the link 0x00002aace2276ad0 is blocked, as a result of which the workers are blocked).

Lockers 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) 

Blocked by 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) 
+2
source

Is the method recursive in some way? Maybe you are using an object inside it that requires the same method?

0
source

but locks on synchronized methods are reentrant, which means that if a thread containing a lock on this object tries to lock it again, it will always succeed.

0
source

It might be worth trying a dead end detecting a bit of code - like this .

The stopQuery lock did not seem to have detected the lock in the stack trace before, but then this lock did not seem to get anywhere - strange ...

 "Worker-2" prio=10 tid=0x00002aad1da66400 nid=0x5165 waiting for monitor entry [0x0000000041b43000..0x0000000041b43b90] java.lang.Thread.State: BLOCKED (on object monitor) at org.eclipse.jdt.internal.core.index.DiskIndex.stopQuery(DiskIndex.java) - waiting to lock <0x00002aacdfe83ea8> (a org.eclipse.jdt.internal.core.index.DiskIndex) at org.eclipse.jdt.internal.core.index.Index.stopQuery(Index.java:192) 

In this bit, there is an expectation of a held lock, but this releases the lock until it receives a notification / timeout:

 "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) 
0
source

Is it possible that DiskIndex.java does not have string information? I assume that you are hanging inside a method where it is trying to get a completely different lock, but you do not see this because there is no line of information in the stack trace.

0
source

All Articles