Applet的生命周期:什么是初始化之间的实际差别()及启动()和destroy()及停止()? [英] Applet lifecycle: what's the practical difference between init() & start(), and destroy() & stop()?
问题描述
借助的javadoc 并的tutorial 对四个小应用程序生命周期方法(信息的init() - GT;开始() - >停止() - GT;破坏()
)。但是,他们在抽象的语言主要是咨询。
The javadoc and tutorial have information about the four applet lifecycle methods (init() -> start() -> stop() -> destroy()
). But they talk mostly in abstract language.
我要找的是当它使一个区别,如果我把的init
我的code VS 启动的具体例子
,同样为摧毁
VS 停止
。到目前为止,我发现的唯一的事情就是在摧毁
方法的教程的描述。它说:
What I'm looking for are concrete examples of when it makes a difference if I put my code in init
vs start
, and similarly for destroy
vs stop
. The only thing I've found so far is in the tutorial's description of the destroy
method. It says:
请注意:保持的实现
破坏方法尽可能短,
因为没有保证
这种方法将完全
执行。 Java虚拟机
长期破坏之前可能会退出
方法完成。
Note: Keep implementations of the destroy method as short as possible, because there is no guarantee that this method will be completely executed. The Java Virtual Machine might exit before a long destroy method has completed.
(我有点震惊,上面是没有的Javadoc。)
(I'm a bit shocked that the above isn't in the javadoc.)
编辑:更具体:任何人都可以提供一个浏览器+ JVM组合的是,在一些特定的动作(切换标签,打的返回按钮等),调用停止
而不是摧毁
(或启动
而不是初始化
)?
to be more specific: Can anyone provide a browser + JVM combo that, upon some specific action (switching tabs, hitting the 'back' button, etc.), invokes stop
but not destroy
(or start
but not init
)?
推荐答案
的init
和摧毁
被调用的时候, applet被分别装载或卸载。这有可能对周围航行时,切换标签,浏览器加载一个小程序,并阻止它,而不是破坏它,等等。
init
and destroy
are called when the applet is loaded or unloaded, respectively. It's possible for a browser to load an applet and stop it, but not destroy it, when navigating around, switching tabs, etc.
启动
和停止
是暂停和恢复小程序,在上述情况下(当小程序而成,或不再,页面上显示)。
start
and stop
are for pausing and resuming the applet, in the case above (when the applet becomes, or ceases to be, shown on a page).
我不知道任何浏览器实际上不会加载保持一个小程序,所以它可能没有多大关系。但是据我了解到的,一般的规则是:
I don't know if any browser actually does keep an applet loaded, so it may not matter much. But as far as i learned it, the general rule is:
-
的init
应该得到的小程序可以运行,但实际上没有设置它在运动。在从的init
回报小程序应该是处于停止状态。 (停止的小程序应使用尽可能少的资源,实际可能,并没有CPU)。 -
启动
应该启动applet中运行(启动线程等)。它一般不会阅读PARAMS和重新加载图像和所有这一切,为应在进行初始化
。 -
停止
应该撤销什么启动
确实...小程序返回已停止状态,但在离开它能够重新启动
。它不应该撤消任何的初始化
的工作,因为这将离开这个小程序无法启动,如果功能正常分离。 -
摧毁
应该做任何最后的清理小程序卸载之前。它基本上撤销的init
。它不应该停止Applet;这是停止的
的工作,应该已经在进行破坏
被调用。
init
should get the applet ready to run, but not actually set it in motion. The applet should be in a "stopped" state upon return frominit
. (A stopped applet should be using as few resources as practically possible, and no CPU.)start
should start the applet running (starting threads, etc). It generally won't read params and reload images and all that, as that should be done ininit
.stop
should undo whatstart
does...returning the applet to the "stopped" state, but leaving it able tostart
again. It should not undo any ofinit
's work, as that would leave the applet unstartable if the functionality is properly separated.destroy
should do any final cleanup before the applet is unloaded. It basically undoesinit
. It should not stop the applet; that'sstop
's job, and should already be done beforedestroy
is called.
这篇关于Applet的生命周期:什么是初始化之间的实际差别()及启动()和destroy()及停止()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!