2010-09-16 119 views
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) 
     ... 

此外,我注意到this thread,其中提到,訪問一個靜態變量可能參與。我們的應用也是如此。問題中的getEAOTableLite中的行引用了靜態方法。

+0

我讀的是這兩個'Component.setFont'調用是否發生在事件派發線程之外的權利?那是你的代碼的結果嗎? – kschneid 2010-09-16 16:32:22

+0

是的,他們是......我在發佈最初的問題後注意到了這一點。我想我第一次通過跟蹤時看到了自己的盲點。你可以在下面看到我的答案。 – 2010-09-16 16:37:59

回答

3

我不知道我是如何錯過它的,但是如果我已經更好地讀了一下堆棧跟蹤,我會發現問題是EAOAlertManager類的靜態初始化將事件全部調用組件.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)