代码拉取完成,页面将自动刷新
CountDownLatch latch = new CountDownLatch(2);
Thread inputThread = new StreamThread(process.getInputStream(), threadName, latch);
Thread outputThread = new StreamThread(process.getErrorStream(), threadName, latch);
inputThread.setUncaughtExceptionHandler(new HeraCaughtExceptionHandler());
outputThread.setUncaughtExceptionHandler(new HeraCaughtExceptionHandler());
inputThread.start();
outputThread.start();
try {
exitCode = process.waitFor();
latch.await();
} catch (InterruptedException e) {
exitCode = Constants.INTERRUPTED_EXIT_CODE;
log(e);
} finally {
process = null;
}
再看取消任务的代码
//强制kill 进程
if (process != null) {
log("WARN Attempting to kill the process ");
try {
process.destroy();
int pid = getProcessId();
String st = "sudo sh -c \"cd; pstree " + pid + " -p | grep -o '([0-9]*)' | awk -F'[()]' '{print \\$2}' | xargs kill -9\"";
String[] commands = {"sudo", "sh", "-c", st};
ProcessBuilder processBuilder = new ProcessBuilder(commands);
try {
process = processBuilder.start();
log("kill process tree success");
} catch (Exception e) {
log(e);
}
} catch (Exception e) {
log(e);
} finally {
process = null;
}
}
String st = "sudo sh -c \"cd; pstree " + pid + " -p | grep -o '([0-9]*)' | awk -F'[()]' '{print \\$2}' | xargs kill -9\"";
String st = "sudo sh -c \"cd; pstree " + pid + " -p | grep -o '([0-9]*)' | sed s/'[()]'/''/g | xargs kill -9\"";
所以可以看出,由于无法杀死子进程,所以实际cancel方法只是把窗口进程,也就是run()中启动的process的进程杀死了,而真正的执行任务的线程并没有杀死,而latch.await()方法则会导致任务的执行线程一直等待,直到子任务执行完毕。这个问题出现在所有shell启动的脚本里。看似杀死了任务,实际任务在后台跑得很快乐
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
登录 后才可以发表评论