0

我们有一个 Swing 应用程序。问题是Windows 7无法关闭 - 消息“还有程序在后台运行”出现,关闭 Windows 的唯一方法是按下强制按钮。

我们有shutdownHook处理程序,它会杀死我们需要杀死的所有东西,但是......此外,分析器在本机JVM方法中显示了2个死锁:

AWT-EventQueue-0 <--- Frozen for at least 12s
sun.awt.windows.WComponentPeer.nativeHandleEvent(AWTEvent)
sun.awt.windows.WComponentPeer.handleEvent(AWTEvent)
sun.awt.windows.WWindowPeer.handleEvent(AWTEvent)
java.awt.Component.dispatchEventImpl(AWTEvent)
java.awt.Container.dispatchEventImpl(AWTEvent)
java.awt.Window.dispatchEventImpl(AWTEvent)
java.awt.Component.dispatchEvent(AWTEvent)
java.awt.KeyboardFocusManager.redispatchEvent(Component, AWTEvent)
java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Component, AWTEvent)
java.awt.DefaultKeyboardFocusManager.dispatchEvent(AWTEvent)
java.awt.Component.dispatchEventImpl(AWTEvent)
java.awt.Container.dispatchEventImpl(AWTEvent)
java.awt.Window.dispatchEventImpl(AWTEvent)
java.awt.Component.dispatchEvent(AWTEvent)
java.awt.EventQueue.dispatchEventImpl(AWTEvent, Object)
java.awt.EventQueue.access$400(EventQueue, AWTEvent, Object)
java.awt.EventQueue$2.run()<2 recursive calls>
java.security.AccessController.doPrivileged(PrivilegedAction, AccessControlContext)
java.security.AccessControlContext$1.doIntersectionPrivilege(PrivilegedAction, AccessControlContext, AccessControlContext)
java.security.AccessControlContext$1.doIntersectionPrivilege(PrivilegedAction, AccessControlContext)
java.awt.EventQueue$3.run()<2 recursive calls>
java.security.AccessController.doPrivileged(PrivilegedAction, AccessControlContext)
java.security.AccessControlContext$1.doIntersectionPrivilege(PrivilegedAction, AccessControlContext, AccessControlContext)
java.awt.EventQueue.dispatchEvent(AWTEvent)
java.awt.SentEvent.dispatch()
java.awt.DefaultKeyboardFocusManager$DefaultKeyboardFocusManagerSentEvent.dispatch()
java.awt.DefaultKeyboardFocusManager.sendMessage(Component, AWTEvent)
java.awt.DefaultKeyboardFocusManager.dispatchEvent(AWTEvent)
java.awt.Component.dispatchEventImpl(AWTEvent)
java.awt.Container.dispatchEventImpl(AWTEvent)
java.awt.Window.dispatchEventImpl(AWTEvent)
java.awt.Component.dispatchEvent(AWTEvent)
java.awt.EventQueue.dispatchEventImpl(AWTEvent, Object)
java.awt.EventQueue.access$400(EventQueue, AWTEvent, Object)
java.awt.EventQueue$2.run()<2 recursive calls>
java.security.AccessController.doPrivileged(PrivilegedAction, AccessControlContext)
java.security.AccessControlContext$1.doIntersectionPrivilege(PrivilegedAction, AccessControlContext, AccessControlContext)
java.security.AccessControlContext$1.doIntersectionPrivilege(PrivilegedAction, AccessControlContext)
java.awt.EventQueue$3.run()<2 recursive calls>
java.security.AccessController.doPrivileged(PrivilegedAction, AccessControlContext)
java.security.AccessControlContext$1.doIntersectionPrivilege(PrivilegedAction, AccessControlContext, AccessControlContext)
java.awt.EventQueue.dispatchEvent(AWTEvent)
java.awt.SequencedEvent.dispatch()
java.awt.EventQueue.dispatchEventImpl(AWTEvent, Object)
java.awt.EventQueue.access$400(EventQueue, AWTEvent, Object)
java.awt.EventQueue$2.run()<2 recursive calls>
java.security.AccessController.doPrivileged(PrivilegedAction, AccessControlContext)
java.security.AccessControlContext$1.doIntersectionPrivilege(PrivilegedAction, AccessControlContext, AccessControlContext)
java.security.AccessControlContext$1.doIntersectionPrivilege(PrivilegedAction, AccessControlContext)
java.awt.EventQueue$3.run()<2 recursive calls>
java.security.AccessController.doPrivileged(PrivilegedAction, AccessControlContext)
java.security.AccessControlContext$1.doIntersectionPrivilege(PrivilegedAction, AccessControlContext, AccessControlContext)
java.awt.EventQueue.dispatchEvent(AWTEvent)
java.awt.EventDispatchThread.pumpOneEventForFilters(int)
java.awt.EventDispatchThread.pumpEventsForFilter(int, Conditional, EventFilter)
java.awt.EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component)
java.awt.EventDispatchThread.pumpEvents(int, Conditional)
java.awt.EventDispatchThread.pumpEvents(Conditional)
java.awt.EventDispatchThread.run()



Thread-1 <--- Frozen for at least 12s
sun.awt.windows.WToolkit.shutdown()
sun.awt.windows.WToolkit.access$200(WToolkit)
sun.awt.windows.WToolkit$2$1.run()
java.lang.Thread.run()

有谁知道可能是什么原因?

4

1 回答 1

2

如果你调用SwingUtilities.invokeAndWait你的关闭钩子,它会死锁。同样,如果您尝试显示任何新窗口。可能大多数 GUI 访问都是危险的。从文档中addShutdownHook

例如,尝试使用其他基于线程的服务(例如 AWT 事件调度线程)可能会导致死锁。

我猜这就是正在发生的事情,尽管查看关闭挂钩的代码可能会有所帮助。你需要“杀死”什么?

于 2013-10-22T13:34:23.740 回答