Olá, sou novo aqui, estou fazendo um programa que rode um ping -t em diversos IP’s, para a aplicação não travar abri uma Thread para o método e mandei executar, o sistema reconhece meu boolean (que setei True ou False, dependendo do estado) no entanto ele não interrompe ou para.
public void runSystemCommand(String command, TextArea texto, Tooltip tip) { Thread thread = new Thread() {
@Override public void run() { try { if (!executando) { Process p = Runtime.getRuntime().exec(command); BufferedReader inputStream = new BufferedReader( new InputStreamReader(p.getInputStream())); String s = ""; texto.setWrapText(true); texto.setText("\r\n"); executando = true; // reading output stream of the command while ((s = inputStream.readLine()) != null) { texto.setText(texto.getText() + "\n" + s + "\n"); texto.setScrollTop(Double.MAX_VALUE); if (texto.getText().length() > Integer.MAX_VALUE) { gerarRelatorio(tip, texto); texto.setText(""); } }
} else if (executando) { System.out.println("Interrompendo"); executando = false; this.stop(); } } catch (Exception e) { e.printStackTrace(); } } }; thread.start();
}
No If e Else o sistema reconhece, mas não consigo dar thread.interrupt() ou thread.stop() pois pedi para inicializar a variavel thread. Se coloco This.stop ou this.interrupt(), simplesmente não faz nada. Alguem tem alguma luz?