permaculture playing cards*
The moose likes Beginning Java and the fly likes Thread close Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Thread close" Watch "Thread close" New topic
Author

Thread close

Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
Hi,
I look in to Thread API. close method is deprecated API. I want to kill or close or destroy the thread. Is there any method?
Thanks,
Angela
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Angela,
Did you notice the text explaining the deprecation? In case you missed it here it is. Read the bold parts twice ...

This method is inherently unsafe. Stopping a thread with Thread.stop causes it to unlock all of the monitors that it has locked (as a natural consequence of the unchecked ThreadDeath exception propagating up the stack). If any of the objects previously protected by these monitors were in an inconsistent state, the damaged objects become visible to other threads, potentially resulting in arbitrary behavior. Many uses of stop should be replaced by code that simply modifies some variable to indicate that the target thread should stop running. The target thread should check this variable regularly, and return from its run method in an orderly fashion if the variable indicates that it is to stop running. If the target thread waits for long periods (on a condition variable, for example), the interrupt method should be used to interrupt the wait.

Regards,
Manfred.
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

You don't have to manually kill the thread. When program control leaves the thread it will die. If you want the thread to die at a certain point just "return" at that point.


Please ignore post, I have no idea what I am talking about.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Thread close