处理java小程序关闭的正确方法是什么?
我们有一个在浏览器窗口之外以窗口方式运行的 Java 小程序。我一直认为通过单击 X 关闭窗口(或右键单击任务栏并选择关闭)即可关闭小程序。
然而,事实证明,当以这种方式关闭时,我们的小程序每次都会使 Safari(在 Mac 和 Windows 中)崩溃。
当小程序关闭时,我应该在代码中执行某些操作吗?代码中想到的第一个罪魁祸首是为 Jabber/XMPP 进行套接字连接的类/库。
We have a java applet that runs windowed outside the browser window. I always assumed that by clicking the X to close the window (or right clicking on the task bar and selecting close) was all you needed to do to close an applet.
However, it turns out that when closed this way, our applet crashes Safari (in both Mac and Windows) every time.
Is there something I am supposed to be doing in the code when an applet closes? The first culprit that comes to mind in the code is a class/library that does a socketed connection for Jabber/XMPP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用小程序中的 destroy() 生命周期回调来处理所有资源你已经打开了(线程,套接字等)。如果不这样做,会发生什么情况可能会因浏览器而异,但根据我的经验(主要是 Firefox),线程通常会继续运行,强制重新启动浏览器以重新加载您的应用程序。不光滑。我还没有看到因此而导致的崩溃,但无论如何,处理资源是一个很好的做法。
Use the destroy() life cycle callback in your applet to dispose of all resources that you have open (threads, sockets etc). What happens if you don't might vary per browser, but in my experience (mainly Firefox) threads usually keep running, forcing a restart of the browser in order to reload your app. Not slick. I haven't seen a crash due to this, but disposing of resources is a good practice anyway.