这是我的主要方法,它包含一个 shutdownhook:
public static void main(String args[]) {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
JOptionPane.showMessageDialog(null, "Shutdown hook");
}
});
/* Create and display the form */
java.awt.EventQueue.invokeLater(
new Runnable() {
@Override
public void run() {
Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
MyFrame frame = new MyFrame();
frame.setVisible(true);
}
});
}
The problem is the JOptionPane
doesn't show up at all. Instead, the frame closes but the app itself still runs.
PS. I can't use the WindowClosing
event because it doesn't fire on the Cmd+Q command on Mac OS X.
调度线程已经关闭,或者很可能在执行您对队列的提交之前关闭。
您需要找到另一种方法来捕获退出事件,关闭挂钩是这样您可以在虚拟机退出时进行清理,因此您确实不想在调用它时在 UI 中占用更多资源。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)