How to stop a thread?

前端 未结 4 1775
逝去的感伤
逝去的感伤 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:58

    Here's what the Java people have to say about why not to call thread.stop and what to do instead.

    http://download.oracle.com/javase/1.5.0/docs/guide/misc/threadPrimitiveDeprecation.html

    The short answer is, you allow the thread entry point function to return.

提交回复
热议问题