• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

how can I kill a thread?

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
You don't like waffles? Well, do you like this tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic