I have a thread executing inside of my applet and I've read that I shouldn't use the stop method of a thread to end it. Here's the scenario. I have one main .asp page that is loaded with every other page. Inside of this .asp page is my applet. So, the applet gets loaded every time someone changes pages. I need to kill the thread and restart it every time the person changes pages. When a certain time has arrived, I show a message box alerting the person that the time has arrived. The problem is that right now, I'm using the applets stop method...
... to try and end the thread the way I read about. But it's not working. Is there another way to do it without resorting to the deprecated stop method of the thread? Thanks.
posted 13 years ago
Your stop method simple drops the reference to the already running thread (at least that's what I gather from your post). That doesn't actually stop anything, it just relies on the garbage collector to one day come around and clean things up; but who knows when the garbage collector will come? Perhaps you want to redesign your thread a bit, so that it is performing inside of a while loop that constantly checks if it should keep running, and stops running when the check tests false. Here's a potential outline for what I'm talking about: