我需要一个无限循环的批处理程序。在这个循环中,他正在做一些事情,然后等待X秒。现在的问题是,我怎样才能阻止程序之外的循环?一个选项是读取一个文件,如果s.o中断,在内部写道“停止”,但如果我总是打开和关闭文件,它的表现如何?无尽循环与控制出口
难道不可能在同一运行时间内启动第二个线程,例如:将布尔运行设置为false或其他东西? 这是我的代码“stop-file”。
Integer endurance = args[3] != null ? new Integer(args[3]) : new Integer(System.getProperty("endurance"));
BufferedReader stop = new BufferedReader(new FileReader(args[4] != null ? args[4] : System.getProperty("StopFile")));
while (!stop.readLine().toUpperCase().equals("STOP"))
{
doSomething(args);
try {
Thread.sleep(endurance);
} catch (InterruptedException e) {
e.printStackTrace();
System.exit(12);
}
stop.close();
stop = new BufferedReader(new FileReader(args[4] != null ? args[4] : System.getProperty("StopFile")));
}