JFrame在打开时陷入一些奇怪的内部死锁

时间:2018-10-08 13:10:27

标签: java swing deadlock

我有一个测试,该测试会在失败时打开JFrame并向我显示一些调试信息。通常它可以正常工作,但是现在我突然遇到了一个怪异的僵局。

当我单击IntelliJ上的转储线程时,我得到了:

```

java.lang.Thread.State: RUNNABLE
    at java.lang.Thread.holdsLock(Native Method)
    at java.awt.Component.checkTreeLock(Component.java:1202)
    at java.awt.Component.getSiblingIndexAbove(Component.java:9858)
    at java.awt.Component.getHWPeerAboveMe(Component.java:9890)
    at java.awt.Component.updateZOrder(Component.java:10154)
    at java.awt.Component.addNotify(Component.java:6953)
    - locked <0x00000006ce23ddd0> (a java.awt.Component$AWTTreeLock)
    at java.awt.Container.addNotify(Container.java:2762)
    - locked <0x00000006ce23ddd0> (a java.awt.Component$AWTTreeLock)
    at javax.swing.JComponent.addNotify(JComponent.java:4740)
    at java.awt.Container.addNotify(Container.java:2773)
    - locked <0x00000006ce23ddd0> (a java.awt.Component$AWTTreeLock)
    at javax.swing.JComponent.addNotify(JComponent.java:4740)
    at java.awt.Container.addNotify(Container.java:2773)
    - locked <0x00000006ce23ddd0> (a java.awt.Component$AWTTreeLock)
    at javax.swing.JComponent.addNotify(JComponent.java:4740)
    at java.awt.Container.addNotify(Container.java:2773)
    - locked <0x00000006ce23ddd0> (a java.awt.Component$AWTTreeLock)
    at javax.swing.JComponent.addNotify(JComponent.java:4740)
    at java.awt.Container.addNotify(Container.java:2773)
    - locked <0x00000006ce23ddd0> (a java.awt.Component$AWTTreeLock)
    at javax.swing.JComponent.addNotify(JComponent.java:4740)
    at java.awt.Container.addNotify(Container.java:2773)
    - locked <0x00000006ce23ddd0> (a java.awt.Component$AWTTreeLock)
    at javax.swing.JComponent.addNotify(JComponent.java:4740)
    at java.awt.Container.addNotify(Container.java:2773)
    - locked <0x00000006ce23ddd0> (a java.awt.Component$AWTTreeLock)
    at javax.swing.JComponent.addNotify(JComponent.java:4740)
    at java.awt.Container.addNotify(Container.java:2773)
    - locked <0x00000006ce23ddd0> (a java.awt.Component$AWTTreeLock)
    at javax.swing.JComponent.addNotify(JComponent.java:4740)
    at java.awt.Container.addNotify(Container.java:2773)
    - locked <0x00000006ce23ddd0> (a java.awt.Component$AWTTreeLock)
    at javax.swing.JComponent.addNotify(JComponent.java:4740)
    at java.awt.Container.addNotify(Container.java:2773)
    - locked <0x00000006ce23ddd0> (a java.awt.Component$AWTTreeLock)
    at javax.swing.JComponent.addNotify(JComponent.java:4740)
    at java.awt.Container.addNotify(Container.java:2773)
    - locked <0x00000006ce23ddd0> (a java.awt.Component$AWTTreeLock)
    at javax.swing.JComponent.addNotify(JComponent.java:4740)
    at java.awt.Container.addNotify(Container.java:2773)
    - locked <0x00000006ce23ddd0> (a java.awt.Component$AWTTreeLock)
    at javax.swing.JComponent.addNotify(JComponent.java:4740)
    at javax.swing.JRootPane.addNotify(JRootPane.java:757)
    at java.awt.Container.addNotify(Container.java:2773)
    - locked <0x00000006ce23ddd0> (a java.awt.Component$AWTTreeLock)
    at java.awt.Window.addNotify(Window.java:770)
    - locked <0x00000006ce23ddd0> (a java.awt.Component$AWTTreeLock)
    at java.awt.Frame.addNotify(Frame.java:487)
    - locked <0x00000006ce23ddd0> (a java.awt.Component$AWTTreeLock)
    at java.awt.Window.pack(Window.java:807)
    at mypackage.LogViewer.viewInFrame(LogViewer.java:380)
    at mypackage.LogViewer.viewInFrame(LogViewer.java:380)
    at mypackage.TestLogger.viewInFrame(TestLogger.java:280)
    at mythingytotest.MyTestClass(MyTestClass.java:87)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:513)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:170)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor$$Lambda$166/945591847.execute(Unknown Source)
    at org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:166)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:113)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:58)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:113)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor$$Lambda$112/1597249648.execute(Unknown Source)
    at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:121)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor$$Lambda$115/1694556038.accept(Unknown Source)

```

没有其他线程包含我的任何代码。即使在那里,我也看不到它怎么会导致死锁。

logviewer组件仅使用图元和图元集合以及香草摆动组件:JComboBox,JTextField,JPanel,JCheckBox

1 个答案:

答案 0 :(得分:0)

Ty毫无意义。

无论如何,以防万一将来某个可怜的失落的灵魂偶然发现类似的情况:

实际上,这里没有僵局。原因是:

1)该logviewer组件内部具有大量事件,并且打开它需要花费很多时间

2)我遇到了一个Ubuntu故障,使jframe完全不可见