AWTAutoShutdown线程暂停VM

时间:2012-10-04 18:58:52

标签: java swing

我正在开发一个遗留项目,其中有人使用swing定时器线程来执行一些服务器调度任务。这段代码不是swing应用程序,它是服务器端java。我知道这不是一个好主意,并且知道可以接受的方法。问题是,我看到一些长时间的VM暂停,每隔几分钟就会在空载下发生。启用详细的gc,我确定它不是垃圾收集。当我在其中一个暂停期间进行线程转储时,我会在下面获得此转储。不知道这个AWTAutoShutdown是否会导致这种暂停,或者当它执行下面显示的activateBlockerThread时它正在做什么?

"AWT-Shutdown" prio=10 tid=0x00007fed5802d000 nid=0x2ef1 in Object.wait() [0x00007fed53e5d000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x000000031e910b90> (a java.lang.Object)
at java.lang.Object.wait(Object.java:485)
at sun.awt.AWTAutoShutdown.run(Unknown Source)
- locked <0x000000031e910b90> (a java.lang.Object)
at java.lang.Thread.run(Unknown Source)

"TimerQueue" daemon prio=10 tid=0x00007fed58597000 nid=0x2a56 in Object.wait() [0x00007fed54737000]
java.lang.Thread.State: BLOCKED (on object monitor)
   at java.lang.Object.wait(Native Method)
   - waiting on <0x000000031e910b90> (a java.lang.Object)
   at java.lang.Object.wait(Object.java:485)
   at sun.awt.AWTAutoShutdown.activateBlockerThread(Unknown Source)
   at sun.awt.AWTAutoShutdown.notifyThreadBusy(Unknown Source)
   - locked <0x000000031e910b90> (a java.lang.Object)
   - locked <0x000000031e9a60c8> (a java.lang.Object)
   at java.awt.EventQueue.postEvent(Unknown Source)
   at java.awt.EventQueue.postEventPrivate(Unknown Source)
   - locked <0x000000031e90eb90> (a java.awt.EventQueue)
   at java.awt.EventQueue.postEvent(Unknown Source)
   at java.awt.EventQueue.invokeLater(Unknown Source)
   at javax.swing.SwingUtilities.invokeLater(Unknown Source)
   at javax.swing.Timer$1.run(Unknown Source)
   at javax.swing.Timer$1.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at javax.swing.Timer.post(Unknown Source)
   - locked <0x000000031e9af7e0> (a javax.swing.Timer)
   at javax.swing.TimerQueue.postExpiredTimers(Unknown Source)
   - locked <0x000000031e90ce60> (a javax.swing.TimerQueue)
   at javax.swing.TimerQueue.run(Unknown Source)
   - locked <0x000000031e90ce60> (a javax.swing.TimerQueue)
   at java.lang.Thread.run(Unknown Source)

1 个答案:

答案 0 :(得分:1)

看起来您可能遇到通知问题。在AWT-Shutdown线程启动后,TimerQueue线程应该已经唤醒(AWTAutShutdown.run方法向监视器发出AWTAutShutdown.activateBlockerThread方法正在等待的信号)。如果你的应用程序长时间冻结并且这些线程没有进展,那么似乎TimerQueue线程没有及时接收到信号。

但是,当您看到应用程序是而不是一个swing / awt应用程序时,我看不出它会如何影响应用程序中的任何其他内容。