什么可能导致Java返回后继续运行
当我进行一些特殊的 GUI 交互时,我遇到了这个问题。 这是我的情况:我使用一个对话框。我不打电话
System.exit() 但稍后返回并离开应用程序。 通常,当 JVM 发现不再存在时,它就会存在。 非守护线程正在运行。但使用这个对话框后, 它不起作用。
我 100% 确信在对话框中调用了 dispose() 有问题以及应用程序的主框架。 我在 IDE 中和运行时都得到了这个 命令行。我可以通过按一下按钮来杀死它 IDE,或从命令行使用 Ctrl-C。
但如果 JVM 正确终止当然会更好 在提交应用程序之前。
任何线索,这是一个已知问题吗?我使用的是 JDK 1.7,但是 问题已经出现在 JDK 1.6 中。
最好的问候
P.S.:刚刚阅读: http://下载。 oracle.com/javase/1.4.2/docs/api/java/awt/doc-files/AWTThreadIssues.html 过去也曾出现过类似的问题。也许这是一个新问题。 过去的问题是: 其他包可以根据内部需要创建可显示的组件,并且永远不会使它们不可显示。请参阅 4515058、4671025,以及 4465537。 我将尝试沿着弹出菜单的显式 setVisible(false) 进行一些尝试。
I have this problem when I do some special GUI interaction.
Here is my situation: I use one dialog. I don't call
System.exit() but leave the application later with a return.
Normally the JVM then exists when it sees that no more
non-deaemon threads are running. But after using this dialog,
it does not work.
I am 100% shure that a dispose() is called on the dialog
in question and also on the main frame of the application.
I get this both in an IDE and when running from
the command line. I can kill it with a button press in the
IDE, or with Ctrl-C from the command line.
But it would of course be better if the JVM correctly terminates
itself before delivering the application.
Any clues, is this a known problem? I am using JDK 1.7, but the
problem show already up in JDK 1.6.
Best Regards
P.S.: Just reading:
http://download.oracle.com/javase/1.4.2/docs/api/java/awt/doc-files/AWTThreadIssues.html
There have been similar issues in the past. Maybe this is a new issue.
The issues in the past were:
Other packages can create displayable components for internal needs and never make them undisplayable. See 4515058, 4671025, and 4465537.
I will try some along an explicit setVisible(false) of the pop up menu.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您确定弹出窗口已被破坏而不仅仅是隐藏吗?我相信默认操作是隐藏,将默认关闭操作设置为 JFRAME.EXIT_ON_CLOSE 可能会解决这个问题。
诊断问题的另一种方法是使用分析器,例如 Netbeans 附带的分析器。在应用程序终止之前使用实时视图和调试点,您可以检查实时对象。
Are you sure the pop up is destroyed and not just hidden? I believe the default action is to hide, and setting the default close operation to JFRAME.EXIT_ON_CLOSE might solve it.
Another way of diagnosing the problem could be to use a profiler, such as the one shipped with Netbeans. Use live view and a debug point just before application should terminate, and you can inspect the live objects.
关闭框架时的默认操作是隐藏它。 UI 线程仍然存在。
如果您希望 JVM 在关闭您创建的框架(可能是您的“弹出窗口”?)时退出,则必须明确说明,例如通过执行
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
,更多文档 这里。可能您只需要 DISPOSE_ON_CLOSE 作为默认CloseOperation。另一种选择是向框架添加一个 windowListener,并在框架关闭时自行决定正确的操作。
The default action when you close a frame is to just hide it. The UI thread is still alive.
If you want the JVM to exit when you close the frame you make (possibly your "popup"?), you have to explicitly say so, e.g. by doing
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
, more docs here. Possibly you only need the DISPOSE_ON_CLOSE as the defaultCloseOperation.An other alternative is to add a windowListener to the frame, and decide the proper action yourself when the frame is closed.
听起来至少有一个线程正在阻塞并且无法响应中断。也许在有问题的线程上使用 .getState() 可能会阐明这个问题。
http://download.oracle .com/javase/6/docs/api/java/lang/Thread.html#getState%28%29
Sounds like at least one thread is blocking and can't respond to an interrupt. Perhaps using .getState() on the thread in question may shed some light on the problem.
http://download.oracle.com/javase/6/docs/api/java/lang/Thread.html#getState%28%29
我遇到了同样的问题,在
EventQueue.invokeLater(new Runnable() {...}
中调用dispose()
为我解决了这个问题I had the same problem, calling
dispose()
in aEventQueue.invokeLater(new Runnable() {...}
resolved it for me