How to forcefully stop thread and start same thread with new variable?

后端 未结 4 2027
太阳男子
太阳男子 2020-12-12 03:58

I want to do some long running task on a button click, if user click again on that button current task forcefully stopped and will do next task ?

4条回答
  •  一生所求
    2020-12-12 04:12

    You have to keep checking a flag in your run method. This flag can be set to false when you want the thread to cancel. The next time your run method checks for this flag, since its false hence it exits the thread. May be you want to use a ThreadPoolExecutor?

提交回复
热议问题