正确关闭小程序

发布于 2024-12-12 22:01:01 字数 594 浏览 0 评论 0原文

在我工作的地方,当用户注销我们的应用程序(一个小程序)时,他们使用 AppletContext.showDocument(URL) 方法,提供所需的注销 JSP。但他们也有代码表明,如果由于某种原因他们无法获得 AppletContext 来简单地调用 Applet.destroy() 方法。

我们使用的是瘦客户端架构,这意味着我们本质上有一堆连接到服务器的哑终端。我提到这一点是因为我们通常会运行数十个甚至数百个 JVM 实例 - 每个小程序一个。

destroy() 方法中,它们会处理所获取的所有资源,然后获取对 Runtime 的引用并调用 runFinalization()gc() - 但它不执行 System.exit() 或等效操作。

我理解的问题

  1. 是,释放资源并让您留在同一网页上,但它对运行小程序的 JVM 有何作用?
  2. 如果我在 destroy() 末尾添加对 System.exit() 的调用,它将对瘦客户端服务器上运行的其他 JVM 产生什么影响?

Where I work they use the AppletContext.showDocument(URL) method when a user logs off our application, which is an applet, providing the desired logoff JSP. But they also have code that says if for some reason they are unable to get an AppletContext to simply call the Applet.destroy() method.

We are using a thin client architecture which means that we essentially have a bunch of dumb terminals connected to a server. I mention this because we will often have dozens if not 100's of instances of JVMs running - one for each applet.

Inside the destroy() method they dispose of all resources they acquired and then get a reference to Runtime and call runFinalization() and gc() - but it does not do a System.exit() or equivalent.

Questions

  1. I understand that frees up resources and leaves you on the same web page but what does it do to the JVM that was running the applet?
  2. If I add a call to System.exit() at the end of the destroy() what will it do to the other JVMs that are running on the thin client server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

厌倦 2024-12-19 22:01:01

对于上下文来说,这都是必要的,因为当页面处于活动状态时,浏览器(或 Java 插件,或两者)都会挂在您的小程序实例上。即使您从 DOM 中删除它或尝试其他技巧来释放该内存,在导航到不同页面之前,您的小程序实例仍会保留,因此您需要在 destroy() 中完全清理。我已经完成了内存分析,显示它在本机代码中的某个地方被引用。

回答您的问题:

  1. 这取决于您的 Java 版本。从 Java 6 update 10(使用下一代插件)开始,一段时间后没有小程序运行 Java 将自行关闭。随着过去一两年 JVM 启动时间的减少,此超时似乎变得更短。
  2. 我不相信小程序(即使是签名的小程序)可以调用System.exit()。如果允许的话,在现代浏览器上它会杀死该浏览器的 JVM 实例,而不是其他浏览器。在过去,它可能会关闭整个浏览器:)

编辑:

实际上,答案 1 的故事还有更多内容……除了 OS X 之外,其他地方都是如此,在 OS X 中,下一代插件并不是默认插件,直到大约在 6u27 左右(10.6 上是 Java for OS X update 5,10.7 从第一天开始)。

For context, this is all necessary because while a page is active browsers (or the Java plugin, or both) hang on to your applet instance. Even if you remove it from the DOM or try other tricks to release that memory, until you navigate to a different page your applet instance is retained so you need to fully clean up in destroy(). I've done memory profiling which shows it's referenced in native code somewhere.

To answer your questions:

  1. This depends on your version of Java. As of Java 6 update 10 (with the next-gen plugin) after a period of time with no applets running Java will shut itself down. This timeout has appeared to get shorter as the JVM startup time has decreased in the last year or two.
  2. I don't believe applets (even signed ones) are allowed to call System.exit(). If it was allowed though, on modern browsers it would kill the instance of the JVM for that browser, none of the others. In the past it would've been likely to shut the entire browser down :)

EDIT:

Actually there's more to the story of Answer 1... that's true everywhere except OS X, where the next-gen plugin wasn't the default until somewhere around 6u27 (On 10.6 it was Java for OS X update 5, and 10.7 from day 1).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文