我是否必须在 Webstart 应用程序中显式调用 System.exit()? [英] Do I have to explicitly call System.exit() in a Webstart application?

查看:26
本文介绍了我是否必须在 Webstart 应用程序中显式调用 System.exit()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我将一个 Swing 应用程序转换为 Webstart.这个过程非常简单,但我发现在关闭所有窗口后,我的应用程序的 JVM 并没有终止.线程转储显示有几个非守护进程线程,特别是 Swing 的 EDT、AWT 和几个与 websart 相关的线程.

Recently I converted a Swing application to Webstart. The process was pretty straightforward, but I found that after I close all windows, my application's JVM did not terminate. The thread dump showed that there are a couple of non-daemon threads, notably Swing's EDT, AWT and a couple of websart related threads.

实际使用的策略是每个窗口在创建时递增一个计数器,在关闭时递减一个.默认关闭操作是 DISPOSE_ON_CLOSE.当计数器达到零时,我停止所有线程池并释放所有 JNI 资源.

The actual strategy used is that each window increments a counter when it is created and decrements one when it is closed. The default close operation is DISPOSE_ON_CLOSE. Wen the counter reaches zero, I stop all threadpools and release all JNI resources.

当我从一个 bat 文件(相同的 JAR)启动应用程序时,它在所有窗口都关闭后正常终止,所以我认为问题与 Webstart 有关系.

When I launched the application from a bat file (same JARs), it terminated fine when all windows were closed, so I figured that the problem has something to do with Webstart.

现在的问题:

  1. 谁能告诉我到底发生了什么?为什么 Webstart 会留下僵尸 JVM?
  2. 有没有办法在不停止 JVM 的情况下显式释放 Webstart 资源?
  3. 我一直认为调用 System.exit() 鼓励不释放资源并依赖操作系统在您之后清理的草率做法(如果您以后重用代码,这可能会导致令人讨厌的意外)...我错过了什么吗?

另见 后续问题 用于检测应用程序是否已被 Webstart 启动.

See also the followup question for detecting whether the app has been launched by Webstart.

推荐答案

因为 WebStart 中的错误,是的.WebStart 启动一个安全线程",用于与 EDT 交互的目的.此 SecureThread 可防止在处理所有窗口和 AWT 资源时自动终止 Java 进程.

Because of bugs in WebStart, yes. WebStart starts up a "secure thread" for it's own purposes that interacts with the EDT. This SecureThread prevents the automatic termination of the Java process one would expect when all windows and AWT resources are disposed.

有关更多信息,请参阅 http://www.pushing-pixels.org/?p=232

For more information see http://www.pushing-pixels.org/?p=232

这篇关于我是否必须在 Webstart 应用程序中显式调用 System.exit()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆