How to kill a java thread?

前端 未结 8 1981
一个人的身影
一个人的身影 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:08

    You can try Thread.stop(), but at your own risk. Optimally, the API you're calling should have a way to interrupt the operation if needed (which is what Thread.interrupt() is for if the API itself does not provide a cleaner way to interrupt its progress, have you tried it?).

提交回复
热议问题