How to kill a java thread?

前端 未结 8 1972
一个人的身影
一个人的身影 2020-12-11 08:26

I google the solution for killing a java thread. And there exists two solutions:

  1. set a flag
  2. using Thread.interrupt

But both of them ar

8条回答
  •  無奈伤痛
    2020-12-11 09:01

    In theory, you could call the deprecated Thread.stop() method. But beware that this could result in your application behaving in unexpected and unpredictable ways ... depending on what the third party library is actually doing. Thread.stop() and friends are fundamentally unsafe.

    The best solution is to modify the 3rd-party library to respond to Thread.interrupt. If you cannot, then ditch it and find / use a better library.

提交回复
热议问题