java 查找JVM分配的内存
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17676179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find the memory allocated by the JVM
提问by David Faizulaev
I am looking for an easy way to find out how much memory the JVM on my computer has allocated to a specific process, i have tried using VisualVM, but it cannot find the process.
我正在寻找一种简单的方法来找出我计算机上的 JVM 分配给特定进程的内存量,我曾尝试使用 VisualVM,但找不到该进程。
I should mention that this it's running a Windows Service, not a regular process.
我应该提到它运行的是 Windows 服务,而不是常规进程。
Any suggestions ?
有什么建议 ?
Thank in advance.
预先感谢。
回答by Bryan Abrams
there is a command that comes with the JRE called jps
which you can use to see all the running java processes. using jps
with -v
gives you the launch parameters of each process.
JRE 附带了一个命令,jps
您可以使用它来查看所有正在运行的 Java 进程。使用jps
with-v
为您提供每个进程的启动参数。
You can see here the launch parameters which will tell you the memory usage of each process.
你可以在这里看到启动参数,它会告诉你每个进程的内存使用情况。
This command should run also on Windows, just replace the terminal with a command prompt.
此命令也应在 Windows 上运行,只需将终端替换为命令提示符即可。
回答by john
I use in android (if you want to know a programatic way):
我在android中使用(如果你想知道一种编程方式):
// get the total memory for my app
long total = Runtime.getRuntime().totalMemory();
// get the free memory available
long free = Runtime.getRuntime().freeMemory();
// some simple arithmetic to see how much i use
long used = total - free;
System.out.println("Used memory in bytes: " + used);
Works for the PC too(just tested)!
也适用于 PC(刚刚测试)!
回答by Jayan
JVisualVM should work for you. There are specific cases where the process is not shown in visualVM.
JVisualVM 应该适合你。在某些特定情况下,visualVM 中未显示该过程。
See some known issues
查看一些已知问题
Local Applications Cannot Be Monitored (Error Dialog On Startup) Description: An error dialog saying that local applications cannot be monitored is shown immediately after VisualVM startup. Locally running Java applications are displayed as (pid ###). Resolution: This can happen on Windows systems if the username contains capitalized letters. In this case, username is UserName but the jvmstat directory created by JDK is %TMP%\hsperfdata_username. To workaround the problem, exit all Java applications, delete the %TMP%\hsperfdata_username directory and create new%TMP%\hsperfdata_UserName directory.
无法监控本地应用程序(启动时出现错误对话框) 描述:VisualVM 启动后立即显示一个错误对话框,说明无法监控本地应用程序。本地运行的 Java 应用程序显示为 (pid ###)。解决方案:如果用户名包含大写字母,这可能会在 Windows 系统上发生。在这种情况下,用户名是 UserName,但 JDK 创建的 jvmstat 目录是 %TMP%\hsperfdata_username。要解决此问题,请退出所有 Java 应用程序,删除 %TMP%\hsperfdata_username 目录并创建新的 %TMP%\hsperfdata_UserName 目录。