Behaviour of stop() and destroy()-methods
I'm one of the developers of a MMO type of game which has a applet based client application. In our application we use stop-method to save the game status and destroy method to check that the stop method ran succesfully, report any caught errors to server and send a logout message.
Recently I have noticed strange behaviour from these two methods. It seems like on some cases (about one in fifty) destroy()-method is called and the applet exits before stop()-method returns. In my effort to try and find the issue I have moved almost all the functionality in stop() method into a try/catch block but while the running stops within that block nothing is caught. When tracing the exact point where the running stops I get half a dozen different places, all of which are within that try / catch and while some of those spots could potentially crash none of them should cause the method to exit (say, a method call in try / catch with only stack trace print in catch block).
I have a few workarounds in my mind but first I'd really like to know what on earth is going on in here. Has anyone else noticed similar behaviour?
No matter, I found the error myself...
As it turns out in some cases Java decides to kill the thread that is running applet.stop() method while it's running and this causes a java.lang.ThreadDeath to be thrown. I discovered this by adding a catch for Throwables as well as Exceptions in the stop method, causing the method to return immediately without any trace of error. How nice of Sun to have such a little feature in the jvm...