0

I googled and found this, other ways to cancel a thread include things like using a boolean flag inside a thread loop, and modify it somewhere else to make thread quit.

Isn't this same ugly, and why Thread.stop()/suspend()/resume() are more dangerous? Any examples or explanations?

Hind Forsum
  • 9,717
  • 13
  • 63
  • 119
  • Short answer: Threads communicate by changing shared variables. If one thread forcibly kills or suspends a second thread, there is no way to know whether the second thread left the shared variables in a consistent, meaningful state or not. – Solomon Slow Dec 11 '18 at 14:17
  • If you check a boolean you can do this at a safe and natural place to stop the thread while leaving shared data in a consistent state. – Peter Lawrey Dec 11 '18 at 18:32

0 Answers0