Reputation: 11260
How do I stop the process of a Java Applet when a user navigates away from the page the applet has been loaded from?
I am using Chrome, and for now to kill the applet, I have to use window's taskbar and kill the process java.exe
Upvotes: 4
Views: 1673
Reputation: 15699
Java applets have lifecycle methods. Those are init
, start
, stop
and destroy
. You should learn to use them, but what's more important, you should learn when a browser calls each of this method.
When you navigate away from your page, stop
is called and you should stop threads you started in start
and cleanup resources if you allocated any. Browsers do not kill JVM on every page reload because it would by extremely inefficient (and for other reasons), so if you want to stop whatever your applet is doing, implement it in stop
method.
Also see here and other links on that page, for further explanation.
Upvotes: 7