我正在编写一个使用java.lang.ProcessBuilder
运行外部可执行文件的Java程序。该程序应该能够监视子进程的运行时间和内存使用情况,并在超过某些预定义限制时终止。
对于基于时间的测量,实现起来非常简单:
boolean inTime = process.waitFor(60, TimeUnit.SECONDS);
但我还没有找到任何方法来观察子进程的内存使用情况。 Java 有什么方法可以实现这一点吗?
提前致谢!
最佳答案
i don't know what you are asking exactly ,but if you are looking for how much memory your method will take while execution or runtime time
Java Mission Control阅读此内容
you will find JFR and Mbeans right hand side after you open JMC(write "jmc" in terminal) and JFR will give you every single method name also it's child method name as well as how much memory they are taking
this is how you can check-::
make a program with 3-4 methods , iterate them more than 5 lac so it will take so much time and you are able to watch what happening while execution
now open flight recorder and go to (memory->Allocations-> Allocations in new tlab-> allocation Profile)
hope you find your ans Here
关于java - 从 Java 运行进程并观察其内存消耗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34107310/