浏览时 Java Applet 没有被杀死 [英] Java Applet not killed when browsing away

查看:25
本文介绍了浏览时 Java Applet 没有被杀死的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户离开加载小程序的页面时,如何停止 Java 小程序的进程?

How do I stop the process of a Java Applet when a user navigates away from the page the applet has been loaded from?

我正在使用 Chrome,现在要杀死小程序,我必须使用窗口的任务栏并杀死进程 java.exe

I am using Chrome, and for now to kill the applet, I have to use window's taskbar and kill the process java.exe

推荐答案

Java 小程序具有生命周期方法.它们是 initstartstopdestroy.您应该学会使用它们,但更重要的是,您应该了解浏览器何时调用每个方法.

Java applets have lifecycle methods. Those are init, start, stop and destroy. You should learn to use them, but what's more important, you should learn when a browser calls each of this method.

当您离开页面时,会调用 stop 并且您应该停止在 start 中启动的线程并清理资源(如果您分配了任何资源).浏览器不会在每个页面重新加载时杀死 JVM,因为它会非常低效(以及其他原因),因此如果您想停止小程序正在执行的任何操作,请在 stop 方法中实现它.

When you navigate away from your page, stop is called and you should stop threads you started in start and cleanup resources if you allocated any. Browsers do not kill JVM on every page reload because it would by extremely inefficient (and for other reasons), so if you want to stop whatever your applet is doing, implement it in stop method.

另请参阅此处和该页面上的其他链接,以获取进一步说明.

Also see here and other links on that page, for further explanation.

这篇关于浏览时 Java Applet 没有被杀死的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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