15,000 Jobs Available in:
Java, ASP, C#, PHP, SQL, SAP, MySQL and many more.
- Class Quick -
The moose likes Threads and Synchronization and the fly likes Stopping a thread Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Stopping a thread" Watch "Stopping a thread" New topic
Author

Stopping a thread

Raghuraman Guruswamy
Ranch Hand

Joined: Aug 10, 2008
Posts: 98
Hi all,

Now that the stop() method has been deprecated, should we have to stop a running thread only using interrupt() method?



Can anyone please review the above code and let me know if its the proper way to stop a thread?

Thanks in advance !

Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 724

The interruption mechanism is the preferred way to implement cancellation, but calling interrupt() should be considered a request for interruption of the target thread; it does not by definition mean that the target thread will halt execution. You're merely asking the thread to interrupt itself at its own convenience. How that request is dealt with may vary.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Edward Harned
Ranch Hand

Joined: Sep 19, 2005
Posts: 262

interrupt() is a mess. Threads interrupt themselves, other threads call interrupt(). There is no definition for what interrupt should do.

Follow the suggestion in the link found in Thread.stop(). Use your own volatile field to indicate "stop."


Ed's latest article: Managing Threads in Android http://coopsoft.com/ar/AndroidArticle.html
 
 
subject: Stopping a thread
 
MyEclipse, The Clear Choice