• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stopping a thread

 
Manikandan Swaminathan
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Edward Harned
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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."
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!