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 ?
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?
2.1m questions
2.1m answers
60 comments
57.0k users