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

查看:204
本文介绍了我是否必须在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.

使用的实际策略是每个窗口在创建时递增计数器,在关闭时递减1。默认关闭操作是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天全站免登陆