aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How to kill a user thread forcefully? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How to kill a user thread forcefully?" Watch "How to kill a user thread forcefully?" New topic
Author

How to kill a user thread forcefully?

Mohit Jain
Ranch Hand

Joined: Jun 04, 2007
Posts: 74
Hi Ranchers

Please tell how do we kill a user thread as no such method is provided by th 'Thread' class.


SCJP 5.0, SCWCD in progress
Manfred Klug
Ranch Hand

Joined: Jun 04, 2007
Posts: 377
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

Joined: Jun 04, 2007
Posts: 74
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

Joined: Jun 04, 2007
Posts: 377
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
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
The basic method for stopping a thread is outlined here.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19064
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to kill a user thread forcefully?