关闭浏览器时发生了一个小程序是什么? [英] What happens to an applet when browser is closed?

查看:213
本文介绍了关闭浏览器时发生了一个小程序是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设我有一个浏览器页面中运行的小程序。
当浏览器用户关闭该怎么办?

Let's suppose I have an applet running within a page in a browser. What happens when the browser is closed by the user?

时小应用程序通知,以便它可以在其一侧执行某种接近动作(关闭连接打开到服务器,清洗静态变量,...)?

Is the applet notified so that it can perform some kind of close action on its side (closing connections opened to a server, cleaning static variables, ...)?

另外,我认为同样的行为将适用于刷新页面或页面导航(而不是浏览器关闭)。浏览器保持打开状态,但小程序了。虽然当你关闭浏览器还关闭JVM,所以我在这一点上不确定。

Also, I assume the same behavior would apply for a page refresh or page navigation (instead of browser close). The browser remains opened but the applet is gone. Although when you close the browser you also close the JVM so I'm unsure at this point.

谢谢,
JB

Thanks, JB

推荐答案

是,在 destroy()方法应该叫浏览器卸载对象之前。

的destroy()是最后四生命周期方法Java小程序的(其余均为的init() 开始()的stop())。他们居然叫在不同的时间取决于您的浏览器虚拟机。如果你想知道什么时候每次调用,实现每个方法的小程序,并且System.out的一些反馈。

destroy() is the last of four "life-cycle methods" of the Java applet (the others are init(), start(), and stop() ). They're actually called at different times depending on your browser and virtual machine. If you'd like to know exactly when each is called, implement each method within your applet, and System.out some feedback.

在理想情况下,销毁()应该是按环境调用,应该只被调用一次。如果它看起来像destroy()方法不会被调用,您可以声明一个公共finalize()方法,它调用破坏。你也可以尝试从JavaScript调用destroy()方法作为窗口对象卸载,但同样,要确保你没有调用destroy()不必要的。

Ideally, destroy() should be called by the environment, and should only be called once. If it seems like destroy() is not being called, you might declare a public finalize() method, which calls destroy. You could also try to call destroy() from javascript as the window object unloads, but again, be sure that you're not calling destroy() unnecessarily.

public void finalize () {
    destroy();
}

这篇关于关闭浏览器时发生了一个小程序是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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