Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

how can I kill a thread?

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
reply
    Bookmark Topic Watch Topic
  • New Topic