我们有 Swing应用。问题是Windows 7
无法关闭 - 消息 “有些程序仍在后台运行” 出现,关闭Windows的唯一方法是按下Force按钮。
我们有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()
有谁知道可能是什么原因?
答案 0 :(得分:2)
如果在关机挂钩中调用SwingUtilities.invokeAndWait
,它将会死锁。同样,如果您尝试显示任何新窗口。可能大多数GUI访问都很危险。来自addShutdownHook
的文档:
尝试使用其他基于线程的服务(例如AWT事件派发线程)可能会导致死锁。
我猜这是发生了什么,虽然查看关闭钩子的代码可能会有所帮助。你需要“杀死”什么?