Your thread can be placed in a while loop and check a boolean variable each time. When you set the variable to false, the loop will end and the thread will also end. To terminate a thread before going through the current loop, you can use the break keyword.
This avoids the use of obsolete methods such as Thread.stop ().
private boolean run = true;
The thread will complete the current task and then stop itself.
If you need to stop the thread before completing the task, you can check the run variable using if / else somewhere in the loop, and end the thread the same way as elsewhere.
while(run){
Andrew Heschl
source share