3

在我们的 java 应用程序启动过程中,我们遇到了一个奇怪的死锁。当我在应用程序上运行 jstack 进行调查时,我看到 AWT-EventQueue 在 Object.wait() 中,但线程仍被标记为 RUNNABLE。我已经包含了线程转储的相关部分,我希望有人可以对这个问题有所了解。

"AWT-EventQueue-0" prio=6 tid=0x5f0a2400 nid=0x19e4 in Object.wait() [0x6007e000]
       java.lang.Thread.State: RUNNABLE
        at com.ge.med.platinum.work.isu.ExamTransaction.getEAOTableLite(ExamTransaction.java:1514)
          ...
          - locked <0x1fc87448> (a java.awt.Component$AWTTreeLock)
          ...

"Thread-63-Pool-9" prio=6 tid=0x5f1a2800 nid=0x1f54 waiting for monitor entry [0x61a9f000]
   java.lang.Thread.State: BLOCKED (on object monitor)
    at java.awt.Component.setFont(Component.java:1777)
    - waiting to lock <0x1fc87448> (a java.awt.Component$AWTTreeLock)
      ...

"Thread-289-Pool-3" prio=6 tid=0x60afe800 nid=0x12b8 waiting for monitor entry [0x623fe000]
   java.lang.Thread.State: BLOCKED (on object monitor)
    at java.awt.Component.setFont(Component.java:1777)
    - waiting to lock <0x1fc87448> (a java.awt.Component$AWTTreeLock)
      ...

另外,我注意到这个线程,其中提到可能涉及访问静态变量。在我们的应用程序中也是如此。有问题的 getEAOTableLite 中的行引用了一个静态方法。

4

2 回答 2

3

我不确定我是如何错过它的,但是如果我更好地阅读了堆栈跟踪,我会发现问题在于 EAOAlertManager 类的静态初始化最终会调用 Component.setFont()方法,被 AWT-EventQueue 阻塞(在 EventQueue 之外调用 setFont() 是非法的)。EventQueue 最终返回到 ExamTransaction.getEAOTableLite,这意味着它将再次引用 EAOAlertManager 类,导致它等待类完成加载。但是 EAOAlertManager 类正在 EventQueue 上等待。我的朋友们,这是一个僵局。

"Thread-289-Pool-3" prio=6 tid=0x60afe800 nid=0x12b8 waiting for monitor entry [0x623fe000]
   java.lang.Thread.State: BLOCKED (on object monitor)
    at java.awt.Component.setFont(Component.java:1777)
    - waiting to lock <0x1fc87448> (a java.awt.Component$AWTTreeLock)
    at java.awt.Container.setFont(Container.java:1554)
    at javax.swing.JComponent.setFont(JComponent.java:2723)
    at javax.swing.LookAndFeel.installColorsAndFont(LookAndFeel.java:191)
    at javax.swing.plaf.basic.BasicPanelUI.installDefaults(BasicPanelUI.java:49)
    at javax.swing.plaf.basic.BasicPanelUI.installUI(BasicPanelUI.java:39)
    at com.ge.med.ptk.laf.CuiPanelUI.installUI(CuiPanelUI.java:53)
    at javax.swing.JComponent.setUI(JComponent.java:662)
    at javax.swing.JPanel.setUI(JPanel.java:136)
    at javax.swing.JPanel.updateUI(JPanel.java:109)
    at javax.swing.JPanel.<init>(JPanel.java:69)
    at javax.swing.JPanel.<init>(JPanel.java:92)
    at javax.swing.JPanel.<init>(JPanel.java:100)
    at javax.swing.JRootPane.createGlassPane(JRootPane.java:528)
    at javax.swing.JRootPane.<init>(JRootPane.java:348)
    at javax.swing.JDialog.createRootPane(JDialog.java:611)
    at javax.swing.JDialog.dialogInit(JDialog.java:593)
    at com.ge.med.plaf.wrapper.WJDialog.dialogInit(WJDialog.java:42)
    at javax.swing.JDialog.<init>(JDialog.java:545)
    at javax.swing.JDialog.<init>(JDialog.java:515)
    at com.ge.med.plaf.wrapper.WJDialog.<init>(WJDialog.java:424)
    at com.ge.med.platinum.gui.util.PlatinumDialog.<init>(PlatinumDialog.java:138)
    at com.ge.med.platinum.gui.util.EAOAlertManager$EAOAlertDialog.<init>(EAOAlertManager.java:450)
    at com.ge.med.platinum.gui.util.EAOAlertManager.<clinit>(EAOAlertManager.java:77)
    at com.ge.med.platinum.work.isu.ExamTransaction.getEAOTableLite(ExamTransaction.java:1514)
于 2010-09-16T16:36:48.870 回答
1

这篇文章似乎直截了当: http ://www.javaworld.com/javaworld/jw-04-1999/jw-04-toolbox.html 有5页。我不知道这对您的应用程序意味着什么,但它应该对您有所帮助。

于 2010-09-16T16:55:23.427 回答