• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to kill Threads

 
Pash Sonar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to kill a thread while executing after some time. How to kill the thread in middle. (stop and destroy methods are deprecated, so dont use)

If any body knows the solution plz help me
 
Sameer Amte
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The above code should help in stopping a thread gracefully or in a forced mode. If your thread is in a wait state then an InterruptedException will be raised in which you should break out of your while loop to terminate your thread.
 
Pash Sonar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sameer Amte:


The above code should help in stopping a thread gracefully or in a forced mode. If your thread is in a wait state then an InterruptedException will be raised in which you should break out of your while loop to terminate your thread.
 
Yaroslav Chinskiy
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest to make continueRunning volatile.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!