How to stop a thread that is running forever without any use

后端 未结 6 2118
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 14:58

In the below code, i have a while(true) loop. considering a situation where there is some code in the try block where the thread is supposed to perform some tasks which take

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 15:32

    The only way to stop an arbitrary thread is by interrupting it. Keep a reference to it then call the interrupt method.

提交回复
热议问题