Boa tarde, estou montando um frame que possui um botão, que ao ser pressionado, executa uma thread. Nesta thread, há a execução de um processo através do Runtime.
Meu problema é o seguinte: como interromper o processo da thread ao apertar o botão novamente, como um start-stop?
O método destroy() não está interrompendo.
Segue meu code:
...
public static boolean isExecuting = false;
public static Process process;
...
public synchronized void getDiff() throws IOException
{
String command = "";
isExecuting = true;
process = Runtime.getRuntime().exec("C:/Windows/system32/cmd.exe");
stdin = process.getOutputStream();
sterr = process.getErrorStream();
command = "svn diff -r " + (getChgset() - 1) + ":" + getChgset() + " " + getUrl() + " > " + getPath() + getChgset() + ".diff" + "\n";
stdin.write(command.getBytes());
stdin.flush();
stdin.close();
boolean failed = false;
BufferedReader brCleanUp = new BufferedReader(new InputStreamReader(sterr));
while ((command = brCleanUp.readLine()) != null)
{
//System.out.print("[Sterr]: "+ command");
printLog("[Error]: " + command, true, true);
failed = true;
}
brCleanUp.close();
if(!failed)
printLog("Diff: "+ getChgset() + " received.", true, false);
exit(failed ? false : true);
}
private void startActionPerformed()
{
Thread t = new Thread()
{
@Override
public void run() {
try {
utils.getDiff();
} catch (IOException ex) {
Logger.getLogger(MainGui.class.getName()).log(Level.SEVERE, null, ex);
}
}
};
if(Utils.isExecuting)
Utils.process.destroy();
else
{
utils.printLog("Capturing diff "+chgset.getValue().toString()+"...", false, false);
t.start();
}