tags:

views:

28

answers:

1

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.

+1  A: 

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.

disown
I've also noted that if I reload the page with the applet, it doesn't restart the VM, that is, singletons etc, are not recreated.
aioobe
Yep, you need to avoid having static variables, singletons and the like. Just code your app so that you can have multiple apps running in parallel on a VM and you will be fine. Good oo practice anyway.
disown
Any recommendations on how to track down the culprit crashing the browser? I added a destroy() and did a disconnect on the Jabber client, and then assigned to null... but still seeing the problem.
Matt
You can attach with jconsole and see if the JVM keeps running after the crash. If it crashes, you should get a hs_err_pidxxx.log somewhere, try to find that. If not, the browser could be crashing independent of the VM. Run your browser in a debugger or try to get a crash dump.
disown