I would like to know how to kill a thread.
public class thread {
private static void metodo(){
new Thread(){
@Override
public void run(){
while(true){
System.out.println("Executando...");
try {
Thread.sleep(2000);
Thread.interrupted();
} catch (InterruptedException ex) {
System.out.println("Interrompido!");
break;
}
}
}
}.start();
}
public static void main(String[] args) {
metodo();
}
}
I would not like to give a simple break in the While, I would like to kill Thread with methods of itself.
I have an application that needs to stop a Thread to run it again, without running the same method in parallel, so my question is.