pararlo a x segundos desde fuera del thread , aqui va el code
Código:
import java.lang.Thread;
/**
*
* @author hpmini
*/
public class Threads extends Thread{
public static boolean running = true;
public void run(){
while(running){
System.out.println("Saludos");
}}
public static void shtdwn(){
running = false;}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Threads Threads1 = new Threads();
Threads1.start();
stopIt stop = new stopIt();
stop.start();
}
}
class stopIt extends Thread{
public void run(){ try{
Thread.sleep(1000);
Threads.shtdwn();
} catch (InterrumpedException iox){}
}
public boolean running = false;
}