How to stop a thread?

前端 未结 4 1773
逝去的感伤
逝去的感伤 2020-11-27 08:15

When a thread is alive, how can I stop the thread? I have given like

if(thread.isAlive()){
    thread.stop();
}

but the method stop is depr

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 08:43

    Better you have to use this method of thread,to stop it.

    Thread.interrupt();
    

    So that you can also save the state of thread.

提交回复
热议问题