java - 从 Java 运行进程并观察其内存消耗

标签 java process child-process

我正在编写一个使用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/

相关文章:

node.js - Node : Send Ctrl+C to a child process on Windows

java - 我应该在哪里打开/关闭 JSF ManagedBean 中的 JMS 连接?

deployment - 谁负责部署?

java - ProcessBuilder导致无法运行程序

javascript - 为什么模块中的函数没有传回主进程?

bash:为什么我不能在后台 shell 中为 SIGINT 设置陷阱?

java - 应用程序无法在 android 9 版本中运行,但可以在以下版本中运行

java - Maven项目没有引用java中的sikuli-api依赖

java - 无法让 VLCJ CaptureTest 工作

c - 在没有主体的 While 循环中从 FIFO(命名管道)读取