关于线程和进程的使用

最近在研究android自动化测试,为了减小log日志,每次循环执行之后清空日志,在循环体中使用线程,如下:

new Thread(new Runnable() {
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
Process p1 = null;
String cmd = "adb logcat -v time > D:\\test.txt";
try {
p1 = Runtime.getRuntime().exec(cmd);
p1.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
).start();

Thread.interrupt();

结果发现线程没有起到作用,不知道问题出在哪儿。。。有知道的大神求指导~

最后直接使用进程的中断来达到目标

String cmd = "adb logcat -v time > D:\\test.txt";

Process pro = Runtime.getRuntime().exec(cmd);
pro.waitFor();
//测试步骤
//清空文件
pro.destory();


猜你喜欢

转载自blog.csdn.net/a420344/article/details/50844045
今日推荐