如果我使用Runtime(freememory()和totalmemory()和gc())类,那么它会给我高于mb的内存(即1000000字节).
但是如果我在任何在线编译器上运行相同的代码,那么它们会显示kb中使用的内存(即1000字节).这是巨大的差异.
这意味着运行时不显示程序使用的实际内存.
我需要计算程序使用的实际内存.这些在线编译器用于计算程序使用的内存的方式是什么?
参考代码 :
ProcessBuilder ps4;
Process pr4 = null;
String batchFile3 = new File(path + "/src/example.sh");
ps4 = new ProcessBuilder(batchFile3.getAbsolutePath());
ps4.redirectErrorStream(true);
ps4.directory(new File(path + "/src/"));
pr4 = ps4.start();
BufferedReade readRun = new BufferedReader(new InputStreamReader(pr4.getInputStream()));
if(pr4.waitFor()==0)
{
}
String line,stre;
while ((line = readRun.readLine()) != null) {
System.out.print("-----" + line);
if (line != null) {
stre += line;
}
}
Run Code Online (Sandbox Code Playgroud)
在这里我得到了stre字符串,它可能是错误或由我正在执行的批处理文件生成的输出.
我想停止批处理文件的执行,如果需要花费4-5秒来执行批处理文件执行过程.
同样在这种情况下,我应该能够返回程序来处理一个块,只有在处理批处理文件的这种延迟发生时,才会执行该块,否则不应该处理该块.