Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to kill a user thread forcefully?

 
Mohit Jain
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers

Please tell how do we kill a user thread as no such method is provided by th 'Thread' class.
 
Manfred Klug
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mohit,

There is such a function. But you should read the API Documentation carefully why you shouldn't use it.
 
Mohit Jain
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manfred

I know we can use depricated method 'stop()' to stop the thread.

But if I dont want to use any depricated method then how to kill a running thread??

Thanks in advance..
 
Manfred Klug
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mohit Jain:
I know we can use depricated method 'stop()' to stop the thread.

But if I dont want to use any depricated method then how to kill a running thread??

Then the answer is: There is no such function. And if you understand the API documentation you will know why.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The basic method for stopping a thread is outlined here.
 
Henry Wong
author
Marshal
Pie
Posts: 21498
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mohit Jain:

I know we can use depricated method 'stop()' to stop the thread.

But if I dont want to use any depricated method then how to kill a running thread??


There is a reason why stop() is deprecated. It is deprecated because when you force a thread to stop, instead of asking it to stop gracefully, you can leave variables in an indeterminate state -- as locks are forced to be released.

stop() is deprecated because there is no guaranteed safe way to force a thread to stop.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic